[CKAD] Kubernetes Certificate Application Developer(CKAD) with Tests 문제 정리
pod volume 관련
컨테이너 볼륨 마운트
- 기본 엠프티볼륨. lifetime이 pod와 같은 컨테이너
containers:- name: containerimage: nginxvolumeMounts:- mountPath: /mount/pathname: volumeNamevolumes:- name: volumeNameemptyDir: {} # 기본적으로 pod의 라이프타임에 따르므로 crush가 될때 지워지지는 않는다. container의 command에서 mkdir로 만드는 것과는 다름,- name: configmapVolumeconfigMap: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/v1kind: NetworkPolicymetadata:name: networkpolicynamespec:policyTypes:- ingress- egresspodSelector: # 정책을 적용할 대상matchLabels:run: appnameingress: #- from:- podSelector:matchLabels:name: frompodname
Ingress
spec: policyTypes:
- ingress
- egress
podSelector:
ingress:
- from:
- podSelector: matchLabels: name: frompodname
- from:
kind: IngressapiVersion: networking.k8s.io/v1metadata:name: ingress-vh-routingannotations:nginx.ingress.kubernetes.io/rewrite-target: /spec:rules:- host: watch.ecom-store.comhttp:paths:- pathType: Prefixpath: "/video"backend:service:name: video-serviceport:number: 8080- host: apparels.ecom-store.comhttp:paths:- pathType: Prefixpath: "/wear"backend:service:name: apparels-serviceport:number: 8080
readiness and liveness
readiness : 처음 수행할 때 정상 수행 중인지 체크 liveness : 수행 중인 pod가 계속 살아있는지 체크
spec:readinessProbe:httpGet:path: /port: 8080livenessProbe:exec:command:- cat- /home/watchdoginitialDelaySeconds: 10periodSeconds: 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: controlplanetolerations:- key: "node-role.kubernetes.io/control-plane"operator: "Exists"effect: "NoSchedule"
secret을 참조하는 환경변수(env)
volume으로 생성하지 않고 바로 떙겨온다.
apiVersion: v1kind: podspec:containers:- name:image:env:- name: EnvVariablevalueFrom:secretKeyRef:name: secretNamekey: secretDataKey
secret의 값을 볼륨으로 바로 마운트
apiVersion: v1kind: podspec:containers:- image:name:volumeMounts:- name: secretVolumemountPath: "/opt/aa"readOnly: truevolumes:- name: secretVolumesecret:secretName: secretName- name: configVolumeconfigMap:ame: configMapName