본문 바로가기
IT 기술/Infra

[cka] Commands and Arguments

by Geunny 2024. 7. 5.
반응형

1. How many PODs exist on the system?
In the current(default) namespace

 

controlplane ~ ➜  k get pods
NAME             READY   STATUS    RESTARTS   AGE
ubuntu-sleeper   1/1     Running   0          38s

 

answer : 1

 

 

2. What is the command used to run the pod ubuntu-sleeper?

 

controlplane ~ ➜  k describe pod ubuntu-sleeper
Name:             ubuntu-sleeper
Namespace:        default
Priority:         0
...
Containers:
  ubuntu:
    Container ID:  containerd://a4e73c5a4f31185f4da9de660223023800562459920577e2a46e9007f9a6225a
    Image:         ubuntu
    Image ID:      docker.io/library/ubuntu@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30
    Port:          <none>
    Host Port:     <none>
    Command:
      sleep
      4800
    State:          Running

 

answer : sleep 4800

 

3. Create a pod with the ubuntu image to run a container to sleep for 5000 seconds. Modify the file ubuntu-sleeper-2.yaml.
Note: Only make the necessary changes. Do not modify the name.

 

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: ubuntu-sleeper-2
  name: ubuntu-sleeper-2
spec:
  containers:
  - command:
      - "sleep"
      - "5000"
    image: ubuntu
    name: ubuntu-sleeper-2
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

 

 

4. Create a pod using the file named ubuntu-sleeper-3.yaml. There is something wrong with it. Try to fix it!
Note: Only make the necessary changes. Do not modify the name.

 

apiVersion: v1
kind: Pod 
metadata:
  name: ubuntu-sleeper-3
spec:
  containers:
  - name: ubuntu
    image: ubuntu
    command:
      - "sleep"
      - 1200    # -> "2000" 문자열로 변경

 

5. Update pod ubuntu-sleeper-3 to sleep for 2000 seconds.
Note: Only make the necessary changes. Do not modify the name of the pod. Delete and recreate the pod if necessary.

controlplane ~ ➜  k edit pod ubuntu-sleeper-3
###
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"ubuntu
-sleeper-3","namespace":"default"},"spec":{"containers":[{"command":["sleep","120
0"],"image":"ubuntu","name":"ubuntu"}]}}
  creationTimestamp: "2024-07-02T14:56:52Z"
  name: ubuntu-sleeper-3
  namespace: default
  resourceVersion: "1059"
  uid: fef83136-bac2-4503-81d5-35d94cca40f0
spec:
  containers:
  - command:
    - sleep
    - "1200"   # -> "2000" 변경
    
    ##
    
    
 controlplane ~ ➜  k edit pod ubuntu-sleeper-3 
error: pods "ubuntu-sleeper-3" is invalid
A copy of your changes has been stored to "/tmp/kubectl-edit-1264881946.yaml"
error: Edit cancelled, no valid changes were saved.


controlplane ~ ✖ k apply -f /tmp/kubectl-edit-1264881946.yaml --force
pod/ubuntu-sleeper-3 configured

 

6. Inspect the file Dockerfile given at /root/webapp-color directory. What command is run at container startup?

FROM python:3.6-alpine

RUN pip install flask

COPY . /opt/

EXPOSE 8080

WORKDIR /opt

ENTRYPOINT ["python", "app.py"]

 

answer: python app.py

 

7. Inspect the file Dockerfile2 given at /root/webapp-color directory. What command is run at container startup?

FROM python:3.6-alpine

RUN pip install flask

COPY . /opt/

EXPOSE 8080

WORKDIR /opt

ENTRYPOINT ["python", "app.py"]

CMD ["--color", "red"]

 

answer : python app.py --color red

 

8. Inspect the two files under directory webapp-color-2. What command is run at container startup?
Assume the image was created from the Dockerfile in this directory.

 

apiVersion: v1
kind: Pod 
metadata:
  name: webapp-green
  labels:
      name: webapp-green
spec:
  containers:
  - name: simple-webapp
    image: kodekloud/webapp-color
    command: ["--color","green"]

 

answer : --color green

 

9.  Inspect the two files under directory webapp-color-3. What command is run at container startup?
Assume the image was created from the Dockerfile in this directory.


apiVersion: v1
kind: Pod 
metadata:
  name: webapp-green
  labels:
      name: webapp-green
spec:
  containers:
  - name: simple-webapp
    image: kodekloud/webapp-color
    command: ["python", "app.py"]
    args: ["--color", "pink"]

 

answer python app.py --color pink

 

10. Create a pod with the given specifications. By default it displays a blue background. Set the given command line arguments to change it to green.

apiVersion: v1 
kind: Pod 
metadata:
  name: webapp-green
  labels:
      name: webapp-green 
spec:
  containers:
  - name: simple-webapp
    image: kodekloud/webapp-color
    args: ["--color", "green"]

 

 

args / command 차이

 

command

 

command 필드는 Docker 이미지의 ENTRYPOINT를 재정의하는 데 사용됩니다. 이는 컨테이너가 시작될 때 실행할 실행 파일을 지정합니다.

 

args

 

args 필드는 command에 제공되는 인수를 지정합니다. command가 지정되지 않은 경우, args는 Docker 이미지의 기본 ENTRYPOINT에 제공됩니다.

 

두 필드의 동작 방식

 

 command args가 모두 지정된 경우, 컨테이너는 지정된 command와 제공된 args를 사용하여 실행됩니다.

 command만 지정된 경우, 컨테이너는 인수 없이 지정된 command를 실행합니다.

 args만 지정된 경우, 컨테이너는 Docker 이미지의 기본 ENTRYPOINT에 제공된 args를 사용하여 실행됩니다.

댓글