Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

전공공부

[K8S - CKA] Application Commands 본문

Study/K8S

[K8S - CKA] Application Commands

monitor 2023. 11. 5. 20:49

1. Commands


docker run ubuntu [COMMAND] : 이런 식으로 코멘트를 지정 할 수 있습니다. 또는, Docker File을 열어서 CMD 부분을 수정합니다.

 

예시로, 

 

CMD ["sleep","5"] 이런식으로요. 그리고, 코멘드와 value는 무조건 분리가 되어야합니다. 

 

CMD ["sleep 5"] 는 안 된다는 거죠.

 

또는 이런식의 구성은 될까요?

 

CMD ["sleep"] 으로 지정 되어 있고 docker run ubuntu-sleeper 10 이렇게 하면 sleep 10이 실행이 될까요?

 

네, 실행이 됩니다.

 

명령줄에 명시되지 않은 명령줄을 보통 실행 시킬때는

 

FROM Ubuntu

 

ENTRYPOINT ["sleep"]

 

CMD ["5"]

 

 

이런 식으로 씁니다. 이렇게 쓰면, Entry Point가 기본 명령줄이 되고 CMD의 값이 기본 명령 value가 되어서 아무것도 지정하지 않고 사용해도 돌아갑니다.

 

2. Commands and Args


 

그래서, K8S에서의 사용 예시를 보자.

 

위에서 정의한 ubuntu-sleeper 이미지를 pod에 가져와서 실행한다고 가정하면 value 값을 어떻게 지정할까요?

 

args 포인트로 지정이 가능합니다.

 

apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: ubuntu-sleeper
    image: ubuntu-sleeper
    command: ["sleeper덮어쓰기"] #Docker의 ENTRYPOINT와 동일
    args: ["10"] #Docker의 CMD란과 동일
  restartPolicy: OnFailure

 

이런식으로 도커 이미지의 변수 덮어 쓰기가 가능합니다.

 

3. Config Maps


 

env으로 container 내부의 응용 프로그램을 설정하는 key value pair를 설정하는 값을 지정하는 개체이다. 

 

적용 순서

 

1. ConfigMap 만들기

 

kubectl create configmap <configmap-name> --from-literal=<key>=<value>

 

or

kubectl create configmap <configmap-name> --from-file=<path-to-file>

 

or

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2022-02-18T19:14:38Z
  name: special-config
  namespace: default
  resourceVersion: "651"
  uid: dadce046-d673-11e5-8cd0-68f728db1985
data:
  special.how: very
  special.type: charm

 

2. Pod 구성 맞추기

(ENV 전체 가져와서 쓰기)

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: registry.k8s.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      env:
        # Define the environment variable
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
              name: special-config
  restartPolicy: Never

 

(single ENV 맞추기)

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: registry.k8s.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      env:
        # Define the environment variable
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              # The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
              name: special-config
              # Specify the key associated with the value
              key: special.how
  restartPolicy: Never