k8s 30

Replication Controller & Replica Sets

Replication Controller helps us run multiple instances of a single pod in the k8s cluster --> providing high availability pod가 죽으면 기존에 선언 된 수 만큼의 새로 pod 띄워 running 상태로 유지 여러 노드들에 걸쳐서 healthy pod 갯수 조절 관여 여러 pod간의 load balance & scaling replication controller는 ReplicaSet보다 이전 기술, 나중에 RS로 대체됨 replication controller definition의 spec.template은 pod의 definition과 똑같다 spec.replicas에 개수를 적어주면 해당 갯수 만큼의 p..

CKA 2021.09.08

Kubernetes Pods

Pod : 한 개 이상의 container로 이루어진 component 1개의 Pod에 1개의 app이 있고, 트래픽 증가로 app이 scale up 해야할 때 pod 안에 app이 추가되는 것이 아닌 pod 가 추가됨. pod 내의 컨테이너 간에는 localhost로 통신이 가능하고, storage space도 share 가능함 Multi-container Pods 같은 pod 안의 container들은 같은 lifecycle, 같은 network(서로 localhost 통신 가능)와 storage 공간을 공유한다. definition의 spec.containers를 array 형태로 여러개의 컨테이너 선언할 수 있음. InitContainers Pod가 running 상태가 되기 전에 초기에 실행되고..

CKA 2021.09.08

ConfigMap & Secrets

ConfigMap kubectl create configmap app-config --from-literal=APP_COLOR=blue --from-literal 옵션 뒤에는 =형태로 변수 넘겨줌 --from-file 옵션으로 외부의 file 참조하여 생성 가능 Pod(deployment)definition 의 spec.containers.envFrom.configMapRef 에 configmap 명 넣어주면 configMap의 data가 pod의 env variable로 추가됨 Secrets 민감 정보를 저장하기 위한 component 저장시 암호화되어 저장됨 kubectl create secret generic app-secret --from-literal=APP_COLOR=blue --from-li..

CKA 2021.09.08

Commands and Arguments

Dockerfile Commands pod의 definition 파일에서 Dockerfile의 Entrypoint 명령어에 argument를 전해주려면 spec.containers.args 에 JSON Array 형식으로 넘겨준다. args 로 넘겨주면 Dockerfile의 CMD override함 Dockerfile의 Entrypoint override하려면 spec.containers.command 에 JSON Array 형식으로 넘겨준다. Arguments spec.containers.env 에서 array 형태로 선언해줌. - name: AAA \ value: bbb 로 key-value 형식 value를 configmap이나 secret에서 가져오고자 하면 value: 대신 valueFrom: ..

CKA 2021.09.08

Monitoring & Logging

Metrics server in-memory monitoring solution 하나의 클러스터에 하나의 metrics server만 node와 pod의 metric을 in-memory에 취합하고 저장 historical metric data를 볼 순 없어서 추가적인 monitoring solution 을 사용해야 함 kubelet의 subcomponente인 cAdvisor에서 pod metric 수집하고 Metrics server으로 보냄 Metrics server는 HPA와 VPA할 때에도 필요함. 설치하면 kubectl top node, pods 명령어 실행 가능 Logging kubectl logs 명령어로 볼 수 있음 Pod에 컨테이너가 하나 이상인 경우 kubectl logs 명령어에 pod..

CKA 2021.09.08

Multiple Schedulers

kubernetes는 여러 개의 custom scheduler를 선언하는 것을 허락한다. binary 다운받아서 --scheduler-name 옵션의 이름 변경하여 실행 pod definition file에서 scheduler 지정하면 원하는 scheduler로 pod 실행시킬 수 있음. spec.schedulerName: 에 scheduler name 설정하면 됨. 제대로 설정되지 않으면 pod는 pending state로 유지됨 scheduler는 pod 형식으로 배포되기 때문에 static pod의 manifests가 위치한 folder에서 yaml 파일 copy 후 scheduler name 옵션 추가하고 저장하면 kubelet이 custom scheduler 배포함 --leader-elect 옵..

CKA 2021.09.07

Static Pods

K8S 클러스터에서 master node와 다른 worker node 없이 오로지 하나의 worker node만 있다면? kubelet은 특정 디렉토리의 definition 파일들을 보고 pod 생성하는 것 뿐 아니라 pod가 살아있는지 확인함 kubelet은 app crash나면 restart도 시키고, 변경 사항이 생기면 recreate도 함 이 디렉토리에서 yaml 삭제하면 pod도 삭제됨 Static pod : API Server의 개입 없이 kubelet이 자체적으로 생성한 pod replicaset나 deployment나 service는 이 디렉토리에 definition 넣어도 생성 못함. 이것들은 master node의 controller가 필요하기 때문. directory는 어느 위치에나 ..

CKA 2021.09.07

DaemonSets

CKA 70/262 클러스터의 모든 node에 하나씩 pod 를 배포할 수 있도록 함 node가 하나 추가되면 pod도 하나 또 추가됨 kube-proxy같은 monitoring agent나 Network agent가 daemonset으로 좋은 예 DaemonSets가 어떻게 pod를 각 worker node에 배포하는지? k8s 1.11버전까지는 각 pod에 nodeName 값 설정해서 각 nodeName으로 배포되도록 함 1.12버전부터는 node affinity와 default scheduler 사용해서 각 worker node에 배포시킴

CKA 2021.09.05

Node Selector & Affinities

특정 pod를 특정 node에 띄우기 위한 방법은 두 가지 NodeSelector spec.nodeSelector로 pod 의 definition에 정의. node에 정의된 label로 key:value 선언 kubectl label nodes =: node에 label 주는 방법 node Selectors로는 or 조건이나 not 조건을 추가할 수 없음 Node Affinity 더욱 복잡하고 다양한 조건을 위한 기능 operator을 In과 NotIn으로 설정할 수 있고, 이의 대상은 values 내의 label value array이다. operator이 exists는 affinity에 선언한 key값이 있는 node들을 대상으로 적용됨. value section은 값을 비교하지 않기 때문에 필요 없..

CKA 2021.09.05

Taints & Tolerations

Taints와 Tolerations 는 어떤 파드가 어떤 node에 놓이면 안되는지를 제한하는 것 taints 와 tolerations 가 없으면 scheduler는 pod를 node에 균등하게 배포함 node에 taint를 설정하고 pod에 toleration을 설정하지 않으면 모든 pod는 node의 taint때문에 해당 node에 배포 불가 taint는 node 대상, tolerations는 pod 대상으로 설정한다 kubectl taint nodes node1 key1=value1:NoSchedule taint-effect 종류 NoSchedule: pod를 해당 node에 신규 배포하지 않음 PreferNoSchedule: pod를 웬만하면 node에 배포를 피하지만 아예 안하진 않음 NoExe..

CKA 2021.09.05