기출 정리
* Pod에서 특정 log만 추출하여 파일로 저장 * ServiceAccount 생성, Role 생성, Role Binding 생성 후 확인 * ETCD snapshot save & restore * Cluster Upgrade (Controlplane Node만 진행) * Pod에 nodeSelector (disktype=ssd) 추가 * Pod를 생성하고 포트는 80, NodePort는 30020인 서비스를 배포 * Taint가 없는 Node의 개수를 파일로 저장 * Node의 상태가 ready 개수를 파일로 저장 * 사용률이 가장 높은 Pod를 특정 label로만 조회해서 파일로 저장 * 특정 Node를 Pod를 다른 Node로 Reschedule하고 해당 Node는 SchedulingDisabled * 특정 Node가 NotReady 상태인데 Ready가 되도록 TroubleShooting * 특정 Deployment에 대해 replicas 수정 * Ingress를 생성해서 이미 생성 되어 있는 서비스와 연결하고 확인 * Networkpolicy를 생성해서 특정 namespace의 Pod만 특정 경로로 연결 * PVC 생성 후 Pod와 PVC 연동 (PV는 이미 존재), PVC 용량 수정 * 기존에 배포된 Pod에 새로운 Container 추가 (Sidecar 패턴) * 이미지 nginx 1.16으로 Deployment 생성 후 이미지를 nginx 1.17로 업그레이드 하기Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Starting 9m14s kube-proxy Normal Starting 9m17s kubelet Starting kubelet. Warning InvalidDiskCapacity 9m17s kubelet invalid capacity 0 on image filesystem Normal NodeHasSufficientMemory 9m17s (x2 over 9m17s) kubelet Node node01 status is now: NodeHasSufficientMemory Normal NodeHasNoDiskPressure 9m17s (x2 over 9m17s) kubelet Node node01 status is now: NodeHasNoDiskPressure Normal NodeHasSufficientPID 9m17s (x2 over 9m17s) kubelet Node node01 status is now: NodeHasSufficientPID Normal NodeAllocatableEnforced 9m17s kubelet Updated Node Allocatable limit across pods Normal RegisteredNode 9m12s node-controller Node node01 event: Registered Node node01 in Controller Normal NodeReady 9m12s kubelet Node node01 status is now: NodeReady Normal NodeNotReady 87s node-controller Node node01 status is now: NodeNotReadyjournalctl -u kubeletssh node01 "service kubelet start"
~~etcd --version~~ etcdctl --versionETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \\ --cacert=<trusted-ca-file> --cert=<cert-file> --key=<key-file> \\ snapshot save <backup-file-location>export ETCDCTL_API=3 etcdctl --data-dir <data-dir-location> snapshot restore snapshot.db1. sudo docker ps -a | grep etcd 2. kubectl get pods
# 문제 노드 확인 $ k get node # ssh 접속 $ ssh wk8s-node-0 # 루트 권한 설정 $ sudo -i # kubelet 서비스 상태 확인 $ systemctl status kubelet ... inactive 상태 확인하기 # 재기동 $ systemctl restart kubelet # 상태 확인 $ systemctl status kubelet ... active 상태 확인
image.png 
image.png # storageclasses를 지정하지 않으면 기본을 사용함 $ k get sc # 확장 가능 확인, AllowVolumeExpansion: True $ k describe sc {storageclasses명} Name: standard IsDefaultClass: Yes Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"},"labels":{"addonmanager.kubernetes.io/mode":"EnsureExists"},"name":"standard"},"provisioner":"k8s.io/minikube-hostpath"} ,storageclass.kubernetes.io/is-default-class=true Provisioner: k8s.io/minikube-hostpath Parameters: <none> MountOptions: <none> ReclaimPolicy: Delete VolumeBindingMode: Immediate Events: <none> # 기본 storageClass 수정 # allowVolumeExpansion: true $ k edit sc standard .............. allowVolumeExpansion: true <=== 추가 # PV 생성, 공식문서 참조(pods/storage/pv-volume.yaml) apiVersion: v1 kind: PersistentVolume metadata: name: task-pv-volume labels: type: local spec: storageClassName: standard <=== 기본으로 수정 capacity: storage: 10Mi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data" $ k apply -f pv.yaml persistentvolume/task-pv-volume created # PVC 생성, 공식문서 참조(pods/storage/pv-claim.yaml) apiVersion: v1 kind: PersistentVolumeClaim metadata: name: task-pv-claim spec: storageClassName: standard <=== 기본으로 수정 accessModes: - ReadWriteOnce resources: requests: storage: 10Mi <== 수정함 $ k apply -f pvc.yaml persistentvolumeclaim/task-pv-claim created # 확인 $ k get pv,pvc NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE persistentvolume/task-pv-volume 10Mi RWO Retain Bound default/task-pv-claim manual 30s NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/task-pv-claim Bound task-pv-volume 10Mi RWO manual 26s # POD 생성, 공식문서 참조(pods/storage/pv-pod.yaml) apiVersion: v1 kind: Pod metadata: name: task-pv-pod spec: volumes: - name: task-pv-storage persistentVolumeClaim: claimName: task-pv-claim containers: - name: task-pv-container image: nginx ports: - containerPort: 80 name: "http-server" volumeMounts: - mountPath: "/usr/share/nginx/html" name: task-pv-storage $ k apply -f pv-pod.yaml pod/task-pv-pod created # pvc 10Mi -> 90Mi 용량 변경 $ k edit pvc task-pv-claim ........... spec: accessModes: - ReadWriteOnce resources: requests: storage: 90Mi <== 변경 storageClassName: manual volumeMode: Filesystem volumeName: task-pv-volume ........... persistentvolumeclaim/task-pv-claim edited[변경 이벤트 검증 확인하기] # 변경 이벤트 확인 # $ k describe pvc task-pv-claim .............. Warning ExternalExpanding 3m11s volume_expand waiting for an external controller to expand this PVCapiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: minimal-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: ingressClassName: nginx-example <== 삭제 rules: - http: paths: - path: /hi <== 수정 pathType: Prefix backend: service: name: my-service <== 수정 port: number: 80 # 적용 $ k apply -f minimal-ingress.yaml ingress.networking.k8s.io/minimal-ingress created # 확인 $ k describe ingress minimal-ingress Name: minimal-ingress Labels: <none> Namespace: default Address: Default backend: <default> Rules: Host Path Backends ---- ---- -------- * /hi my-service:80 (10.244.0.154:8080,10.244.0.155:8080,10.244.1.17:8080 + 2 more...)# serviceaccount 생성 $ k create serviceaccount john $do > sa.yaml # apply $ k apply -f sa.yaml # role 생성 $ k -n development create role developer --resource=pods --verb=create $ k -n development create rolebinding developer-role-binding \\ --role=developer --user=john# 특정노드 이름 조회 $ k get no --show-labels | grep k8s-node-0 # # node drain # DaemonSet에서 관리하는 포드가 있는 경우 # 노드를 성공적으로 비우려면 --ignore-daemonsetswith를 지정해야한다. $ k drain --ignore-daemonsets k8s-node-0 # node 상태 확인 $ k get no -o wide # pod의 위치확인 $ k get po -o wide# Check which nodes are ready JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \\ && kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True" # Check which nodes are ready with custom-columns kubectl get node -o custom-columns='NODE_NAME:.metadata.name,STATUS:.status.conditions[?(@.type=="Ready")].status'$ k get node -o custom-columns='NODE_NAME:.metadata.name,STATUS:.status.conditions[?(@.type=="Ready")].status' --no-headers| wc -l > 파일명# 특정 namespace에 control-plane(샘플)라벨로 필터하여 cpu로 정렬 k top po -n kube-system -l tier=control-plane --sort-by=cpu # 답안작성 $ echo '노드이름' > 답변 파일 위치
# pod 생성 $ k run nginx-resolver --image nginx # pod expose $ k expose pod nginx-resolver -name nginx-resolver-service\\ --port 80 --target-port 80 --type NodePort # 확인 $ k get svc nginx-resolver-service -o yaml$ k scale deployment/nginx-deployment --replicas=10# ErrorMessage 로그필터 $ k logs podName | grep ErrorMessage > 답안경로# 노드 확인 $ k get no => 노드 갯수 3개 확인 # k describe no | grep -i taint Taints: <none> <== 없는 것은 none으로 확인 # 답안작성 echo '2' > 답안파일 경로
Last updated