728x90

공식 문서의 taints 와 tolerations 에 대해서는 아래의 링크를 참고하면 된다. taints 는 노드에 적용되어 <수용 가능한 Pod 의 특성 정의>정도인 것 같고, tolerations 는 Pod 에 적용되어 <내가 동작할 수 있는 Node 를 선택하기 위한 특성 정의>라고 보면 될 것 같다.

 

테인트(Taints)와 톨러레이션(Tolerations)

노드 어피니티는 노드 셋을 (기본 설정 또는 어려운 요구 사항으로) 끌어들이는 파드의 속성이다. 테인트 는 그 반대로, 노드가 파드 셋을 제외할 수 있다. 톨러레이션 은 파드에 적용되며, 파드

kubernetes.io

 


노드에 설정된 taints 를 확인하기 위해서는 kubectl 에서 describe 옵션을 사용하면 된다.

$ kubectl describe node node01
Name:               node01
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
...
Annotations:        flannel.alpha.coreos.com/backend-data: null
                    flannel.alpha.coreos.com/backend-type: host-gw
...
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Mon, 25 Jan 2021 07:43:27 +0000
Taints:             <none>
Unschedulable:      false
Lease:
  HolderIdentity:  node01
  AcquireTime:     <unset>

 

특정 노드에 특정 key-value 와 effect 값을 지정하여 taints 를 설정. 아래는 spray 를 key 로, mortein 을 value 로, effect 는 NoSchedule 로 지정한 예임

$ kubectl taint nodes node01 spray=mortein:NoSchedule
node/node01 tainted

 

Pod 을 생성할 때 배치된 Node 가 없다면 (이 경우에는 Taints 로 특정한 값이 부여된 Node 밖에 없다) Pod 이 생성되지 못하고 Pending 상태로 머무르며, 상세 에러 내용이 taints 와 tolerations 에 대한 내용이 노출된다.

$ kubectl get pods
NAME       READY   STATUS    RESTARTS   AGE
mosquito   0/1     Pending   0          88s

$ kubectl describe pod mosquito
Name:         mosquito
Namespace:    default
Priority:     0
Node:         <none>
...
...
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason            Age               From               Message
  ----     ------            ----              ----               -------
  Warning  FailedScheduling  6s (x3 over 92s)  default-scheduler  0/2 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 1 node(s) had taint {spray: mortein}, that the pod didn't tolerate.

 

Pod 을 Taints 가 지정된 Node 로 배포하기 위해서는 Pod 의 스펙에 관련된 값을 지정해 주어야 한다.

$ cat create_pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: bee
spec:
  containers:
  - image: nginx
    name: bee
  tolerations:
  - key: spray
    value: mortein
    effect: NoSchedule
    operator: Equal
    
$ kubectl create -f create_pod.yaml
pod/bee created

 

노드에 할당되어 있는 taints 값의 변경은 아래의 명령으로 수행할 수 있다. 예시는 controlplane 노드에 대하여 값을 부여하고 삭제하는 예시임.

$ kubectl taint nodes controlplane node-role.kubernetes.io/master:NoSchedule
node/controlplane tainted
$
$ kubectl taint nodes controlplane node-role.kubernetes.io/master:NoSchedule-
node/controlplane untainted
728x90
728x90

쿠버네티스 환경에서 자원들을 그룹 단위로 관리하기 위해서 사용하는 것이 labels 이다. labels 를 이용해 key-value 페어로 다양한 속성 값을 지정할 수 있으며, 이렇게 지정한 값들은 --selector 파라메터를 사용하여 아래와 같이 자원을 조회할 때 사용할 수 있다.

$ kubectl get pods --selector env=dev
NAME          READY   STATUS    RESTARTS   AGE
app-1-2k2pg   1/1     Running   0          71s
app-1-bbdsn   1/1     Running   0          71s
app-1-w7d94   1/1     Running   0          71s
db-1-dzcnf    1/1     Running   0          70s
db-1-f6f8m    1/1     Running   0          70s
db-1-lb72h    1/1     Running   0          70s
db-1-tlmjt    1/1     Running   0          70s

 

kubectl get 구문에서 자원의 형태에 관계 없이 목록을 가져오는 경우 all 을 쓰면 되는 것 같다. 

$ kubectl get all --selector env=prod
NAME              READY   STATUS    RESTARTS   AGE
pod/app-1-zzxdf   1/1     Running   0          6m43s
pod/app-2-hj6qs   1/1     Running   0          6m44s
pod/auth          1/1     Running   0          6m43s
pod/db-2-5nmrk    1/1     Running   0          6m43s

NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/app-1   ClusterIP   10.106.145.187   <none>        3306/TCP   6m43s

NAME                    DESIRED   CURRENT   READY   AGE
replicaset.apps/app-2   1         1         1       6m44s
replicaset.apps/db-2    1         1         1       6m43s

 

--selector 는 여러개의 key, value 를 값으로 받을 수 있는데, 아래와 같이 콤마(,)로 구분자를 넣어서 필요한 labels 를 나열하면 된다.

$ kubectl get pods --selector env=prod,bu=finance,tier=frontend
NAME          READY   STATUS    RESTARTS   AGE
app-1-zzxdf   1/1     Running   0          10m

 

labels 를 활용하여 ReplicaSet 을 만드는 yaml 설정은 아래와 같다.

// replicaset.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: replicaset-1
spec:
  replicas: 2
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx
        
// Create replicaset
$ kubectl create -f replicaset-definition-1.yaml
replicaset.apps/replicaset-1 created

// Check
$ kubectl get pods --selector tier=frontend
NAME                 READY   STATUS    RESTARTS   AGE
app-1-2k2pg          1/1     Running   0          14m
app-1-bbdsn          1/1     Running   0          14m
app-1-w7d94          1/1     Running   0          14m
app-1-zzxdf          1/1     Running   0          14m
app-2-hj6qs          1/1     Running   0          14m
replicaset-1-9hcpb   1/1     Running   0          91s

 

 

 

CKA 자격 시험, namespace 를 활용한 몇 가지 커맨드 정리

Kubenetes 를 사용하면서 namespace 를 통해 큰 단위의 리소스 구분을 해줘야 하는 경우가 종종 생깁니다. namespace 를 감안하여 사용할 수 있는 몇 가지 명령어들 중 udemy 강의 실습에서 나온 커맨드를

ondemand.tistory.com


 

 

Certified Kubernetes Administrator (CKA) Practice Exam Tests

Prepare for the Certified Kubernetes Administrators Certification with live practice tests right in your browser - CKA

www.udemy.com

 

열심히 공부하고 있는 강의는 위의 링크를 참고하세요!
제휴마케팅을 통해 소정의 수수료를 지급 받을 수 있습니다

728x90
728x90

CKA (Certified Kubenetes Administrator) 시험을 꽤 실무적인 시험으로 알려져 있습니다. 단답형 지식을 묻는 질문이 주류를 이루고 있어 스펙을 많이 기억해야 하는 다른 시험과 달리 실제 터미널 환경에서 쿠버네티스에 대한 컨트롤을 얼마나 잘 하고 이해하고 있는지를 확인하는 시험입니다. 네, 아직 취득한건 아닙니다 ㅎㅎ 

원격으로 감독관이 컴퓨터 환경을 감시(?)하며 시험이 진행된다고 알려져 있어서 따로 정리한 레퍼런스를 활용하는 것이 어렵다고 합니다. 따라서 유용한 커맨드들을 기억해 두고 시험에 임하면 좋다고 하네요. 듣고 있는 강의에서 정리해준 몇 가지 커맨드를 잊지 않기 위해 정리해 봅니다. 

 

Certified Kubernetes Administrator (CKA) Practice Exam Tests

Prepare for the Certified Kubernetes Administrators Certification with live practice tests right in your browser - CKA

www.udemy.com


 

NGINX Image 를 이용하여 NGINX Pod 생성하기

kubectl run nginx --image=nginx

 

Deployment 생성하기

kubectl create deployment --image=nginx nginx

 

Deployment 구성을 위한 Yaml 템플릿 생성하기 (단, 배포 없이)

kubectl create deployment --image=nginx nginx --dry-run=client -o yaml

 

Deployment 구성을 위한 Yaml 템플릿을 4개 ReplicaSets 를 갖는 구성으로 생성 (단, 배포 없이)

kubectl create deployment --image=nginx nginx --dry-run=client --replicas=4 -o yaml > nginx-deployment.yaml

 

예제 시험문제를 몇 가지 풀다보니 손으로 Yaml 파일을 구성해야 하는 시나리오가 종종 나오는 것 같습니다. 시행착오를 줄이고 시간을 단축하기 위해, 위의 명령들로 템플릿을 생성해서 변경하는 방식이 아무래도 시험 볼 때 마음을 편안하게 해주겠죠? 기초적인 명령들이지만 익숙하지 않다보니... 일단 여기까지!


 

본 포스팅은 제휴마케팅 링크를 포함하고 있으며 소정의 수수료를 지급받을 수 있습니다. 

728x90

+ Recent posts