문제1
How many PODs exist on the system?
In the current(default) namespace
풀이
controlplane ~ ➜ k get po
NAME READY STATUS RESTARTS AGE
ubuntu-sleeper 1/1 Running 0 2m7s
문제2
What is the command used to run the pod ubuntu-sleeper?
풀이
controlplane ~ ➜ k get po -o jsonpath='{..command}'
["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.
풀이
controlplane ~ ➜ vi ubuntu-sleeper-2.yaml
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-2
spec:
containers:
- name: ubuntu
image: ubuntu
- 기존에 이 내용 이었음
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-2
spec:
containers:
- name: ubuntu
image: ubuntu
command:
- sleep
- "5000"
문제4
Create a pod using the file named ubuntu-sleeper-3.yaml. There is something wrong with it. Try to fix it!
Pod Name: ubuntu-sleeper-3
Command: sleep 1200
풀이
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-3
spec:
containers:
- name: ubuntu
image: ubuntu
command:
- "sleep"
- 1200
- 기존에 위와 같은 내용
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-3
spec:
containers:
- name: ubuntu
image: ubuntu
command:
- sleep
- "1200"
문제5
Update pod ubuntu-sleeper-3 to sleep for 2000 seconds.
Pod Name: ubuntu-sleeper-3
Command: sleep 2000
풀이
---
spec:
containers:
- command:
- sleep
- "2000"
image: ubuntu
---
- 위와 같이 yaml 파일 command 부분을 수정해주고 파드 삭제 후 재생성 해줌
문제6
Inspect the file Dockerfile given at /root/webapp-color directory. What command is run at container startup?
풀이
controlplane ~ ➜ cat /root/webapp-color/Dockerfile
FROM python:3.6-alpine
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
- 커맨드는 python app.py임
문제7
Inspect the file Dockerfile2 given at /root/webapp-color directory. What command is run at container startup?
풀이
controlplane ~ ➜ cat /root/webapp-color/Dockerfile2
FROM python:3.6-alpine
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
CMD ["--color", "red"]
- 컨테이너가 시작되면 ENTRYPOINT 가 먼저 수행되고 CMD는 인자 값으로 제공됨
- 정답은 python app.py --color red
문제8
Inspect the two files under directory webapp-color-2. What command is run at container startup?
풀이
controlplane ~/webapp-color-2 ➜ ls
Dockerfile webapp-color-pod.yaml
controlplane ~/webapp-color-2 ➜ cat *
FROM python:3.6-alpine
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
CMD ["--color", "red"]
apiVersion: v1
kind: Pod
metadata:
name: webapp-green
labels:
name: webapp-green
spec:
containers:
- name: simple-webapp
image: kodekloud/webapp-color
command: ["--color","green"]
- Dockerfile에 명령어를 설정하고 Pod 에서 또 명령어를 설정한 문제임
- 헷갈리면 안되는게 커맨드는 이미지보다 파드가 우선시 됨 --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.
풀이
controlplane ~/webapp-color-3 ➜ cat *
FROM python:3.6-alpine
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
CMD ["--color", "red"]
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"]
- 위에서도 말했듯이 커맨드는 파드가 우선시됨 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.
Pod Name: webapp-green
Image: kodekloud/webapp-color
Command line arguments: --color=green
풀이
- 처음에는 명령형으로 해결하려 했는데 이런 애매한 문제는 그냥 선언형으로 하는 게 맞는듯
piVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: webapp-green name: webapp-green spec: containers: - args: - --color - green image: kodekloud/webapp-color name: webapp-green resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}
- args를 설정해줘서 command line의 인자 값을 설정해줌
'자격증 > Kubernetes CKA' 카테고리의 다른 글
[CKA] 명령어 정리 - 1 (1) | 2024.01.02 |
---|---|
[CKA] Practice Test - Env Variables (0) | 2024.01.01 |
[CKA] Troubleshooting (0) | 2023.12.31 |
[CKA] Install "Kubernetes the kubeadm way" (0) | 2023.12.31 |
[CKA] Networking - 3 (0) | 2023.12.30 |