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

Kubenetes 를 사용하면서 namespace 를 통해 큰 단위의 리소스 구분을 해줘야 하는 경우가 종종 생깁니다. namespace 를 감안하여 사용할 수 있는 몇 가지 명령어들 중 udemy 강의 실습에서 나온 커맨드를 정리해 봅니다. 몇 일 쉬고 다시 들으려니 또 까먹은 것들이 많아서 당혹스럽네요 ㅜㅜ 듣고 있는 CKA Udemy 강의는 아래 링크입니다. 

 

 

 

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

 


redis 이미지를 사용하는 간단한 pod 생성 코드

apiVersion: v1
kind: Pod

metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: redis

 

Pod 를 특정 Namespace 에 생성하기

kubectl create -f pod.yaml --namespace=finance

 

모든 Namespace 의 Pod 목록 확인하기

kubectl get pods --all-namespaces

 

특정 Namespace 의 Pod 목록 확인하기

kubectl get pods --namespace=research

 

redis 이미지를 사용하는 간단한 pod 생성 코드 + namespace 지정

apiVersion: v1
kind: Pod

metadata:
  name: redis
  nemaspace: finance <-- 추가된 부분
spec:
  containers:
  - name: redis
    image: redis

 

기본 namespace(default) 를 특정 namespace 로 고정하기

// 현재의 context 를 가져온 뒤 research namespace 를 기본 값으로 변경
kubectl config set-context $(kubectl config current-context) --namespace=research

 

namespace 의 생성

// yaml 을 이용하는 방법
// namespace.yml
apiVersion: v1
kind: Namespace
metadata:
  name: new-namespace

// 생성한 파일을 이용하여 namespace 생성 
$ kubectl create namespace -f namepsace.yml
// 커맨드라인 명령으로 namespace 생성
kubectl create namespace new-namespace

 


 

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

 

 

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