[CKAD] Kubernetes Certificate Application Developer(CKAD) with Tests 문제 정리

pod volume 관련

컨테이너 볼륨 마운트

  1. 기본 엠프티볼륨. lifetime이 pod와 같은 컨테이너
containers:
- name: container
image: nginx
volumeMounts:
- mountPath: /mount/path
name: volumeName
volumes:
- name: volumeName
emptyDir: {} # 기본적으로 pod의 라이프타임에 따르므로 crush가 될때 지워지지는 않는다. container의 command에서 mkdir로 만드는 것과는 다름,
- name: configmapVolume
configMap:
name: configmapname
# item으로 필요한 값을 파일 형태로 매핑하거나.. 아니면 다 가지고 온다.
# 예를 들어, configmap의 default.conf 아이템에 파일 정보를 담았다면 아래와 같이 별도로 땡겨올 수 있다.
items:
- key: default.conf # configmap의 아이템 키
path: path_of_default.conf # 마운팅한 볼륨 내의 파일 경로

NetworkPolicy

네트워크 enablewjdcordp eogks 정책에 대한 설정 기본적으로 모든 트래픽이 in/out(ingress/egress)로 허용되어 있으나, networkpolicy를 이용하여 특정 pod에 정책을 걸면 걸린 룰만 허용되고 모두 비허용된다.

pod 간 허용

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: networkpolicyname
spec:
policyTypes:
- ingress
- egress
podSelector: # 정책을 적용할 대상
matchLabels:
run: appname
ingress: #
- from:
- podSelector:
matchLabels:
name: frompodname

Ingress

spec: policyTypes:

  • ingress
  • egress podSelector: ingress:
    • from:
      • podSelector: matchLabels: name: frompodname
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: ingress-vh-routing
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: watch.ecom-store.com
http:
paths:
- pathType: Prefix
path: "/video"
backend:
service:
name: video-service
port:
number: 8080
- host: apparels.ecom-store.com
http:
paths:
- pathType: Prefix
path: "/wear"
backend:
service:
name: apparels-service
port:
number: 8080

readiness and liveness

readiness : 처음 수행할 때 정상 수행 중인지 체크 liveness : 수행 중인 pod가 계속 살아있는지 체크

spec:
readinessProbe:
httpGet:
path: /
port: 8080
livenessProbe:
exec:
command:
- cat
- /home/watchdog
initialDelaySeconds: 10
periodSeconds: 5

pod 내 특정 컨테이너 로그 중 일부만 뽑기

kubectl logs dev-pod-dind-878516 -c log-x | grep WARNING > /opt/dind-878516_logs.txt

nodeselector

controlplane에만 pod를 배치시키고 싶다면?

spec:
nodeSelector:
kubernetes.io/hostname: controlplane
tolerations:
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"

secret을 참조하는 환경변수(env)

volume으로 생성하지 않고 바로 떙겨온다.

apiVersion: v1
kind: pod
spec:
containers:
- name:
image:
env:
- name: EnvVariable
valueFrom:
secretKeyRef:
name: secretName
key: secretDataKey

secret의 값을 볼륨으로 바로 마운트

apiVersion: v1
kind: pod
spec:
containers:
- image:
name:
volumeMounts:
- name: secretVolume
mountPath: "/opt/aa"
readOnly: true
volumes:
- name: secretVolume
secret:
secretName: secretName
- name: configVolume
configMap:
ame: configMapName