🔥 CKAD 예상 문제 22선 (문제 + 정답)

2026. 2. 22. 20:19k8s

1️⃣ Deployment 생성

📝 문제

nginx 이미지로 Deployment api-deploy 3 replicas 생성

✅ 정답

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deploy
  namespace: test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api-deploy
  template:
    metadata:
      labels:
        app: api-deploy
    spec:
      containers:
      - name: nginx
        image: nginx

2️⃣ RollingUpdate 무중단 설정

📝 문제

Pod 수가 줄어들지 않도록 설정

✅ 정답

strategy:
  type: RollingUpdate
  rollingUpdate:
    maxSurge: 1
    maxUnavailable: 0

3️⃣ maxSurge 퍼센트 설정

📝 문제

10 replicas 기준 20% surge 허용

✅ 정답

maxSurge: 20%

4️⃣ maxUnavailable 퍼센트 설정

📝 문제

30%까지 삭제 허용

✅ 정답

maxUnavailable: 30%

5️⃣ Canary 70:30 구성

📝 문제

current=7, canary=3
Service 하나로 트래픽 분산

✅ 정답

selector:
  app: myapp
kubectl scale deploy current --replicas=7
kubectl scale deploy canary --replicas=3

6️⃣ Service selector 수정

📝 문제

Endpoint none 해결

✅ 정답

selector:
  app: api-deploy

7️⃣ ConfigMap env 주입

env:
- name: APP_MODE
  valueFrom:
    configMapKeyRef:
      name: app-config
      key: APP_MODE

8️⃣ Secret env 주입

env:
- name: DB_PASS
  valueFrom:
    secretKeyRef:
      name: db-secret
      key: password

9️⃣ Resource 설정

resources:
  requests:
    memory: "30Mi"
  limits:
    memory: "60Mi"

🔟 PVC 생성

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
  namespace: test
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

1️⃣1️⃣ InitContainer 구성

initContainers:
- name: init-con
  image: busybox
  command: ["sh","-c","echo hello > /data/index.html"]

1️⃣2️⃣ LivenessProbe

livenessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5

1️⃣3️⃣ ReadinessProbe

readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5

1️⃣4️⃣ NodePort 변경

type: NodePort
ports:
- port: 80
  targetPort: 80
  nodePort: 30100

1️⃣5️⃣ Label 추가

kubectl label pod <pod> protected=true

1️⃣6️⃣ Annotation 추가

kubectl annotate pod <pod> protected="do not delete"

1️⃣7️⃣ ServiceAccount 적용

serviceAccountName: custom-sa

1️⃣8️⃣ NetworkPolicy Ingress 제한

policyTypes:
- Ingress
ingress:
- from:
  - podSelector:
      matchLabels:
        app: frontend

1️⃣9️⃣ NetworkPolicy Egress DNS 허용

policyTypes:
- Egress
egress:
- ports:
  - protocol: UDP
    port: 53
  - protocol: TCP
    port: 53

2️⃣0️⃣ Imperative → YAML

kubectl create deployment test --image=nginx --dry-run=client -o yaml > deploy.yaml

2️⃣1️⃣ Scale 수정

kubectl scale deploy api-deploy --replicas=5

2️⃣2️⃣ 이미지 업데이트

kubectl set image deploy/api-deploy nginx=nginx:1.25

좋은 지적 👍
CKAD에서 Job / CronJob은 실제로 자주 나오는 유형이다.
지금 22문제 세트에 빠져 있는 게 맞다.

그럼 시험에 나오는 스타일로 Job + CronJob 문제 추가해서 보완해줄게.


🔥 2️⃣3️⃣ Job 생성

📝 문제

Namespace test에 다음 조건의 Job을 생성하라.

  • name: batch-job
  • image: busybox
  • 명령: echo hello; sleep 10
  • 성공 3회 완료 후 종료

✅ 정답

apiVersion: batch/v1
kind: Job
metadata:
  name: batch-job
  namespace: test
spec:
  completions: 3
  template:
    spec:
      containers:
      - name: job
        image: busybox
        command: ["sh","-c","echo hello; sleep 10"]
      restartPolicy: Never

🔥 2️⃣4️⃣ 병렬 Job 실행

📝 문제

동시에 2개씩 실행하면서 총 6회 완료하도록 설정하라.


✅ 정답

spec:
  completions: 6
  parallelism: 2

🔥 2️⃣5️⃣ 실패 재시도 제한

📝 문제

Job 실패 시 4번까지만 재시도하도록 설정하라.


✅ 정답

spec:
  backoffLimit: 4

🔥 2️⃣6️⃣ CronJob 생성

📝 문제

매 1분마다 실행되는 CronJob을 생성하라.

  • name: cron-test
  • image: busybox
  • 명령: date

✅ 정답

apiVersion: batch/v1
kind: CronJob
metadata:
  name: cron-test
  namespace: test
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cron
            image: busybox
            command: ["sh","-c","date"]
          restartPolicy: Never

🔥 2️⃣7️⃣ CronJob 시작 지연 제한

📝 문제

시작 지연을 30초로 제한하라.


✅ 정답

spec:
  startingDeadlineSeconds: 30

🔥 2️⃣8️⃣ CronJob 동시 실행 제한

📝 문제

이전 Job이 실행 중이면 새 Job 실행 금지


✅ 정답

spec:
  concurrencyPolicy: Forbid

🚀 전체 반영 올인원 YAML

아래는 위 핵심들을 포함한 종합 예시.

apiVersion: v1
kind: Namespace
metadata:
  name: test
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: test
data:
  APP_MODE: "prod"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-deploy
  namespace: test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api-deploy
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: api-deploy
    spec:
      serviceAccountName: custom-sa
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        env:
        - name: APP_MODE
          valueFrom:
            configMapKeyRef:
              name: app-config
              key: APP_MODE
        resources:
          requests:
            memory: "30Mi"
          limits:
            memory: "60Mi"
        readinessProbe:
          httpGet:
            path: /
            port: 80
        livenessProbe:
          httpGet:
            path: /
            port: 80
---
apiVersion: v1
kind: Service
metadata:
  name: api-svc
  namespace: test
spec:
  type: NodePort
  selector:
    app: api-deploy
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30100
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: current
  namespace: test
spec:
  replicas: 7
  selector:
    matchLabels:
      app: myapp
      version: current
  template:
    metadata:
      labels:
        app: myapp
        version: current
    spec:
      containers:
      - name: app
        image: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: canary
  namespace: test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
      version: canary
  template:
    metadata:
      labels:
        app: myapp
        version: canary
    spec:
      containers:
      - name: app
        image: nginx
---
apiVersion: v1
kind: Service
metadata:
  name: myapp-svc
  namespace: test
spec:
  selector:
    app: myapp
  ports:
  - port: 80
    targetPort: 80
---
apiVersion: batch/v1
kind: Job
metadata:
  name: batch-job
  namespace: test
spec:
  completions: 3
  parallelism: 1
  backoffLimit: 4
  template:
    spec:
      containers:
      - name: job
        image: busybox
        command: ["sh","-c","echo hello; sleep 10"]
      restartPolicy: Never
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: cron-test
  namespace: test
spec:
  schedule: "* * * * *"
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 30
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cron
            image: busybox
            command: ["sh","-c","date"]
          restartPolicy: Never
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: restrict-egress
  namespace: test
spec:
  podSelector:
    matchLabels:
      app: api-deploy
  policyTypes:
  - Egress
  egress:
  - ports:
    - protocol: UDP
      port: 53
    - protocol: TCP
      port: 53