CKA를 준비해보자 40일차 - mock exam2

0

CKA

목록 보기
40/43

문제1

nginx:alpine image를 사용하는 nginx-pod를 배포하도록 하자.

kubectl run nginx-pod --image nginx:alpine

문제2

redis:alpine image를 사용하는 messagin pod 배포하되, label로 tier=msg를 설정하도록 하자.

kubectl run messaging --image redis:alpine --labels="tier=msg"

문제3

apx-x9984574 namespace를 만들도록 하자.

kubectl create namespace apx-x9984574

문제4

node들 리스트를 json format으로 가져와서 /opt/outputs/nodes-z3444kd9.json에 저장하도록 하자.

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

문제5

messaging-service service를 만들어서 messaging application을 6379 port로 노출시키도록 하자.

  • messaging label 확인
kubectl get po messaging --show-labels 
NAME        READY   STATUS    RESTARTS   AGE     LABELS
messaging   1/1     Running   0          8m17s   tier=msg
  • service manifest 생성
kubectl create service clusterip messaging-service --tcp=6379:6379 -o yaml --dry-run=client > service.yaml
  • selector를 수정하도록 하자.
vi ./service.yaml

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: messaging-service
  name: messaging-service
spec:
  ports:
  - name: 6379-6379
    port: 6379
    protocol: TCP
    targetPort: 6379
  selector:
    tier: msg
  type: ClusterIP
status:
  loadBalancer: {}
  • service 생성
kubectl create -f ./service.yaml

문제6

hr-web-app이라는 deployment를 만들도록 하자. image는 kodekloud/webapp-color를 사용하고 replicas는 2로 하자.

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

문제7

busybox image를 사용하고 sleep 1000 command를 실행하는 static-busybox pod를 controlplane node에 만들도록 하자. 단, static pod로 만들도록 하자.

static pod를 배포시키는 위치는 default로 /etc/kubernetes/manifests이다.

kubectl run --image busybox static-busybox --dry-run=client -o yaml  --command -- sleep 1000 > /etc/kubernetes/manifests/pod.yaml

문제8

finance namespace에 temp-bus pod를 만들되 image는 reids:alpine으로 만들도록 하자.

kubectl create ns temp-bus
kubectl run temp-bus --image redis:alpine --namespace finance

문제9

orange pod가 만들어졌는데 문제를 해결하고 정상복구하도록 하자.

  • 문제 확인
kubectl logs orange init-myservice 
sh: sleeeep: not found
  • 수정
kubectl get pod orange  -o yaml > orange.yaml
kubectl delete -f ./orange.yaml 
vi ./orange.yaml
...
initContainers:
  - command:
    - sh
    - -c
    - sleep 2;
...
kubectl create -f ./orange.yaml 
  • 확인
kubectl get pod orange 
NAME     READY   STATUS    RESTARTS   AGE
orange   1/1     Running   0          15s

문제10

hr-web-apphr-web-app-service를 사용하여 808030082로 노출시키도록 하자.

  • label확인
kubectl get deployments.apps hr-web-app --show-labels 
NAME         READY   UP-TO-DATE   AVAILABLE   AGE   LABELS
hr-web-app   2/2     2            2           35m   app=hr-web-app
  • service manifest 생성
kubectl create service nodeport hr-web-app-service --tcp=8080:8080 --node-port=30082 -o yaml --dry-run=client > nodeport.yaml
  • label selector 매칭
vi ./nodeport.yaml
...
  selector:
    app: hr-web-app
  type: NodePort
...
  • nodeport service 생성
kubectl create -f ./nodeport.yaml

문제 11

json path query를 사용하여 모든 node들의 osImage 결과를 /opt/outputs/nodes_os_x43kj56.txt에 넣도록 하자.

kubectl get nodes -o=jsonpath={.items[*].status.nodeInfo.osImage} > /opt/outputs/nodes_os_x43kj56.txt

문제12

다음의 주어진 조건을 만족하는 Persistent Volume을 만들도록 하자.

  1. name: pv-analytics
  2. storage: 100Mi
  3. mode: ReadWriteMany
  4. host path: /pv/data-analytics
  • pv 생성
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-analytics
spec:
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /pv/data-analytics

0개의 댓글