Q1. Deploy a pod named nginx-pod using the nginx:alpine image.
Once done, click on the Next Question button in the top right corner of this panel. You may navigate back and forth freely between all questions. Once done with all questions, click on End Exam. Your work will be validated at the end and score shown. Good Luck!
- Name: nginx-pod
- Image: nginx:alpine
A1.
kubectl run nginx-pod --image=nginx:alpine
controlplane ~ ➜ kubectl run pod nginx-pod --image=nginx:alpine --dry-run=client -o yaml > nginx.yaml
controlplane ~ ➜ cat nginx.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: pod
name: pod
spec:
containers:
- args:
- nginx-pod
image: nginx:alpine
name: pod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
controlplane ~ ➜ kubectl apply -f nginx.yaml
pod/pod created
Q2. Deploy a messaging pod using the redis:alpine image with the labels set to tier=msg.
- Pod Name : messaging
- Image: redis:alpine
- Labels: tier=msg
A2.
controlplane ~ ✖ kubectl run pod messaging --image=redis:alpine --labels=tier=msg --dry-run=client -o yaml > messaging.yaml
controlplane ~ ➜ cat messaging.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
tier: msg
name: pod
spec:
containers:
- args:
- messaging
image: redis:alpine
name: pod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
controlplane ~ ➜ vi messaging.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
tier: msg
name: messaging ## name 변경
spec:
containers:
- args:
- messaging
image: redis:alpine
name: pod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
controlplane ~ ➜ kubectl apply -f messaging.yaml
Q3.Create a namespace named apx-x9984574.
- namespace: apx-x9984574
A3.
controlplane ~ ➜ kubectl create namespace apx-x9984574
controlplane ~ ➜ kubectl get ns
Q4. Get the list of nodes in JSON format and store it in a file at /opt/outputs/nodes-z3444kd9.json.
A4.
kubectl get nodes -o json > /opt/outputs/nodes-z3444kd9.json
kubectl describe node controlplane
kubectl get nodes -o yaml > no.yaml
Q5. Create a service messaging-service to expose the messaging application within the cluster on port 6379.
Use imperative commands
- Service: messaging-service
- Port: 6379
- Type: ClusterIp
- Use the right labels
A5.
kubectl expose pod messaging --port=6379 --name messaging-service
controlplane ~ ➜ vi svc.yaml
apiVersion: v1
kind: Service
metadata:
name: messaging
spec:
type: ClusterIP
ports:
- name: messaging-service
protocol: TCP
port: 80
targetPort: 6379
Q6. Create a deployment named hr-web-app using the image kodekloud/webapp-color with 2 replicas.
- Name: hr-web-app
- Image: kodekloud/webapp-color
- Replicas: 2
A6.
controlplane ~ ➜ kubectl create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2 --dry-run=client -o yaml > hr.yaml
controlplane ~ ➜ cat hr.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: hr-web-app
name: hr-web-app
spec:
replicas: 2
selector:
matchLabels:
app: hr-web-app
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: hr-web-app
spec:
containers:
- image: kodekloud/webapp-color
name: webapp-color
resources: {}
status: {}
controlplane ~ ➜ kubectl apply -f hr.yaml
deployment.apps/hr-web-app created
Q7. Create a static pod named static-busybox on the controlplane node that uses the busybox image and the command sleep 1000.
- Name: static-busybox
- Image: busybox
A7.
kubectl run --restart=Never --image=busybox static-busybox --dry-run=client -oyaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml
Q8. Create a POD in the finance namespace named temp-bus with the image redis:alpine.
- Name: temp-bus
- Image Name: redis:alpine
A8.
kubectl run temp-bus --image=redis:alpine --namespace=finance --restart=Never
Q9. A new application orange is deployed. There is something wrong with it. Identify and fix the issue.
A9.
To know more details of orange pod:
$ kubectl describe po orange
and look under the initContainers section. There is an issue with the given command.
To update the pod with an easiest way by running command:
$ kubectl edit po orange
It's not possible to update the changes in the running pod so after saving the changes. It will create a temporary file in the default location /tmp/.
Use that manifest file and replace with the existing pod:
$ kubectl replace -f /tmp/kubectl-edit-xxxx.yaml --force
Above command will delete the existing pod and will recreate the new pod with latest changes
Q10. Expose the hr-web-app as service hr-web-app-service application on port 30082 on the nodes on the cluster.
The web application listens on port 8080.
- Name : hr-web-app-service
- Type: NodePort
- Endpoints: 2
- Port: 8080
- NodePort: 30082
A10.
kubectl expose deployment hr-web-app --type=NodePort --port=8080 --name=hr-web-app-service --dry-run=client -o yaml > hr-web-app-service.yaml
Now, in generated service definition file add the nodePort field with the given port number under the ports section and create a service.
Q11. Use JSON PATH query to retrieve the osImages of all the nodes and store it in a file /opt/outputs/nodes_os_x43kj56.txt .
The osImages are under the nodeInfo section under status of each node.
A11.
kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os_x43kj56.txt
Q12. Create a Persistent Volume with the given specification.
- Volume Name : pv-analytics
- Storage: 100Mi
- Access modes: ReadWriteMany
- Host Path: /pv/data-analytics
A12.
Solution manifest file to create a persistent volume pv-analytics as follows:
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
spec:
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
hostPath:
path: /pv/data-analytics
--
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
labels:
type: local
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteMany
hostPath:
path: "/pv/data-analytics"
'클라우드 및 인프라 > CKA' 카테고리의 다른 글
[CKA] Udemy - Mock Exam3 문제풀이 (0) | 2023.08.05 |
---|---|
[CKA] Udemy - Mock Exam2 문제풀이 (0) | 2023.07.24 |
CKA 자격증 신청하기 (0) | 2023.06.15 |
[CKA] Udemy - Troubleshooting - control plane failure 문제풀이 (0) | 2023.05.29 |
[CKA] Udemy - Troubleshooting - worker node failure 문제풀이 (0) | 2023.05.29 |