Udemy Labs - Certified Kubernetes Administrator with Practice Tests - Mock Exam - 1 문제 풀이

hyereen·2024년 6월 2일

Kubernetes

목록 보기
4/53

문제 1

Weight: 6
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

docs

  1. kubectl run: https://kubernetes.io/docs/reference/kubectl/generated/kubectl_run/#examples

정답

kubectl run nginx-pod --image=nginx:alpine

문제 2

Weight: 8
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

docs

  1. labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

정답

controlplane ~ ✖ cat > 2.yaml
apiVersion: v1
kind: Pod
metadata:
  name: messaging
  labels:
    tier: msg
spec:
  containers:
  - name: messaging
    image: redis:alpine

controlplane ~ ➜  kubectl apply -f 2.yaml
pod/messaging created

문제 3

Weight: 4
Create a namespace named apx-x9984574.
Namespace: apx-x9984574

정답

kubectl create namespace apx-x9984574

문제 4

Weight: 7
Get the list of nodes in JSON format and store it in a file at /opt/outputs/nodes-z3444kd9.json.
Task completed

docs

  1. json format: https://kubernetes.io/docs/reference/kubectl/jsonpath/

정답

controlplane ~ ➜  kubectl get nodes -o json > /opt/outputs/nodes-z3444kd9.json

문제 5

Weight: 12
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

정답

  • type 대문자 주의!
kubectl expose pod messaging --port=6379 --name=messaging-service --type=ClusterIP

문제 6

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

정답

kubectl create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2

문제 7

Weight: 8
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

정답

  • command 위치가 -o yaml 다음!
  • on the controlplane node -> 주의! 위치가 /etc/kubernetes/manifests/아래가 됨
controlplane ~ ✖  kubectl run --image=busybox static-busybox --dry-run=client -oyaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

문제 8

Weight: 12
Create a POD in the finance namespace named temp-bus with the image redis:alpine.
Name: temp-bus
Image Name: redis:alpine

정답

controlplane ~ ✖ kubectl run temp-bus --image=redis:alpine -n=finance
pod/temp-bus created

문제 9

Weight: 8
A new application orange is deployed. There is something wrong with it. Identify and fix the issue.
Issue fixed

정답

  • 먼저 orange 로그 확인
ontrolplane ~ ✖ kubectl logs orange
Defaulted container "orange-container" out of: orange-container, init-myservice (init)
Error from server (BadRequest): container "orange-container" in pod "orange" is waiting to start: PodInitializing
  • orange 파드 내 init-myservice 로그 확인
controlplane ~ ✖ kubectl logs orange init-myservice
sh: sleeeep: not found
  • orange yaml파일 생성한 후 sleeeep을 sleep으로 고치고 뒤에 ;도 삭제
controlplane ~ ➜  vi orange_md.yaml

controlplane ~ ✖ cat orange_or.yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2024-06-02T15:30:29Z"
  name: orange
  namespace: default
  resourceVersion: "7845"
  uid: 3cb2871c-dbff-439f-8b85-6c37b3612251
spec:
  containers:
  - command:
    - sh
    - -c
    - echo The app is running! && sleep 3600
    image: busybox:1.28
    imagePullPolicy: IfNotPresent
    name: orange-container
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-8fsw6
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  initContainers:
  - command:
    - sh
    - -c
    - sleeeep 2;
    image: busybox
    imagePullPolicy: Always
    name: init-myservice
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-8fsw6
      readOnly: true
  nodeName: controlplane
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-8fsw6
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:31Z"
    status: "True"
    type: PodReadyToStartContainers
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    message: 'containers with incomplete status: [init-myservice]'
    reason: ContainersNotInitialized
    status: "False"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    message: 'containers with unready status: [orange-container]'
    reason: ContainersNotReady
    status: "False"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    message: 'containers with unready status: [orange-container]'
    reason: ContainersNotReady
    status: "False"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - image: busybox:1.28
    imageID: ""
    lastState: {}
    name: orange-container
    ready: false
    restartCount: 0
    started: false
    state:
      waiting:
        reason: PodInitializing
  hostIP: 192.21.108.6
  hostIPs:
  - ip: 192.21.108.6
  initContainerStatuses:
  - containerID: containerd://a794eeb02db49b52095d7502a127d93b1b56b41b9c92ccfe3276868783593793
    image: docker.io/library/busybox:latest
    imageID: docker.io/library/busybox@sha256:5eef5ed34e1e1ff0a4ae850395cbf665c4de6b4b83a32a0bc7bcb998e24e7bbb
    lastState:
      terminated:
        containerID: containerd://a794eeb02db49b52095d7502a127d93b1b56b41b9c92ccfe3276868783593793
        exitCode: 127
        finishedAt: "2024-06-02T15:31:56Z"
        reason: Error
        startedAt: "2024-06-02T15:31:56Z"
    name: init-myservice
    ready: false
    restartCount: 4
    started: false
    state:
      waiting:
        message: back-off 1m20s restarting failed container=init-myservice pod=orange_default(3cb2871c-dbff-439f-8b85-6c37b3612251)
        reason: CrashLoopBackOff
  phase: Pending
  podIP: 10.244.0.10
  podIPs:
  - ip: 10.244.0.10
  qosClass: BestEffort
  startTime: "2024-06-02T15:30:29Z"

controlplane ~ ➜  cat orange_md.yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2024-06-02T15:30:29Z"
  name: orange
  namespace: default
  resourceVersion: "7845"
  uid: 3cb2871c-dbff-439f-8b85-6c37b3612251
spec:
  containers:
  - command:
    - sh
    - -c
    - echo The app is running! && sleep 3600
    image: busybox:1.28
    imagePullPolicy: IfNotPresent
    name: orange-container
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-8fsw6
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  initContainers:
  - command:
    - sh
    - -c
    - sleep 2
    image: busybox
    imagePullPolicy: Always
    name: init-myservice
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-8fsw6
      readOnly: true
  nodeName: controlplane
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-8fsw6
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:31Z"
    status: "True"
    type: PodReadyToStartContainers
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    message: 'containers with incomplete status: [init-myservice]'
    reason: ContainersNotInitialized
    status: "False"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    message: 'containers with unready status: [orange-container]'
    reason: ContainersNotReady
    status: "False"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    message: 'containers with unready status: [orange-container]'
    reason: ContainersNotReady
    status: "False"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2024-06-02T15:30:29Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - image: busybox:1.28
    imageID: ""
    lastState: {}
    name: orange-container
    ready: false
    restartCount: 0
    started: false
    state:
      waiting:
        reason: PodInitializing
  hostIP: 192.21.108.6
  hostIPs:
  - ip: 192.21.108.6
  initContainerStatuses:
  - containerID: containerd://a794eeb02db49b52095d7502a127d93b1b56b41b9c92ccfe3276868783593793
    image: docker.io/library/busybox:latest
    imageID: docker.io/library/busybox@sha256:5eef5ed34e1e1ff0a4ae850395cbf665c4de6b4b83a32a0bc7bcb998e24e7bbb
    lastState:
      terminated:
        containerID: containerd://a794eeb02db49b52095d7502a127d93b1b56b41b9c92ccfe3276868783593793
        exitCode: 127
        finishedAt: "2024-06-02T15:31:56Z"
        reason: Error
        startedAt: "2024-06-02T15:31:56Z"
    name: init-myservice
    ready: false
    restartCount: 4
    started: false
    state:
      waiting:
        message: back-off 1m20s restarting failed container=init-myservice pod=orange_default(3cb2871c-dbff-439f-8b85-6c37b3612251)
        reason: CrashLoopBackOff
  phase: Pending
  podIP: 10.244.0.10
  podIPs:
  - ip: 10.244.0.10
  qosClass: BestEffort
  startTime: "2024-06-02T15:30:29Z"
  • 기존 orange 파드를 새로운 orange로 대체함
controlplane ~ ➜  kubectl replace -f orange_md.yaml --force
pod "orange" deleted
pod/orange replaced

문제 10

Weight: 10
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

docs

  1. nodeport: https://kubernetes.io/docs/concepts/services-networking/service/#nodeport-custom-port

정답

  • 먼저 yaml파일을 만들어줌
k expose deployment hr-web-app --name=hr-web-app-service --port=8080 --type=NodePort --dry-run=client -o yaml > 10.yaml
 k expose deployment hr-web-app --name=hr-web-app-service --port=8080 --type=NodePort --dry-run=client -o yaml 
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: hr-web-app
  name: hr-web-app-service
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: hr-web-app
  type: NodePort
status:
  loadBalancer: {}
  • docs1을 보고 nodePort를 추가해서 수정해줌
controlplane ~ ✖ vi 10.yaml

controlplane ~ ➜  cat 10.yaml 
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: hr-web-app
  name: hr-web-app-service
spec:
  ports:
  - port: 8080
    protocol: TCP
    nodePort: 30082
  selector:
    app: hr-web-app
  type: NodePort
status:
  loadBalancer: {}
  
controlplane ~ ➜  kubectl apply -f 10.yaml
service/hr-wep-app-service created

문제 11

Weight: 6
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.
Task Completed

docs

  1. jsonpath: https://kubernetes.io/docs/reference/kubectl/jsonpath/

정답

  • docs1의 예시들을 보고 응용할 줄 알아야함
  • 대괄호 유의
  • osImages가 아니라 osImage임을 유의
  • 만들고 확인해봐야 함
controlplane ~ ➜  kubectl get nodes -o jsonpath="{.items[*]['status.nodeInfo.osImages']}" > /opt/outputs/nodes_os_x43kj56.txt
controlplane ~ ➜   cat /opt/outputs/nodes_os_x43kj56.txt
Ubuntu 22.04.4 LTS

문제 12

Weight: 8
Create a Persistent Volume with the given specification: -
Volume name: pv-analytics
Storage: 100Mi
Access mode: ReadWriteMany
Host path: /pv/data-analytics
Is the volume name set?
Is the storage capacity set?
Is the accessMode set?
Is the hostPath set?

docs

  1. persistent volumes: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volumes

정답

  • docs 1보고 문제 조건에 맞게 수정
controlplane ~ ➜  cat > 12.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-analytics
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/pv/data-analytics"

controlplane ~ ➜  kubectl apply -f 12.yaml
persistentvolume/pv-analytics created

0개의 댓글