컨테이너 오케스트레이션을 위한 Kubernetes (22.05.17)

박민선·2022년 5월 17일
0

Workload - Pod

https://kubernetes.io/ko/docs/concepts/workloads/pods/

파드: 컨테이너의 모음
쿠버네티스가 관리할 수 있는 가장 작은 워크로드는 파드

파드 생성 및 관리

명령형 커맨드로 파드 생성

kubectl run myweb --image httpd

파드 목록 확인

kubectl get pods

특정 파드 확인

kubectl get pods myweb

파드 상세 정보

kubectl get pods -o wide
kubectl get pods -o yaml
kubectl get pods -o json
kubectl describe pods myweb

애플리케이션 로그

kubectl logs myweb

파드 삭제

kubectl delete pods myweb

YAML 파일로 파드 정의

myweb.yaml

apiVersion: v1
kind: Pod 
metadata:
  name: myweb
spec:
  containers:
    - name: myweb
      image: httpd
      ports:
        - containerPort: 80
          protocol: TCP

kubectl explain pods

파일을 이용한 pods 생성

kubectl create -f myweb.yaml

파일을 이용한 pods 확인

kubectl get -f myweb.yaml
kubectl describe -f myweb.yaml

파일을 이용한 pods 삭제

kubectl delete -f myweb.yaml

kubectl 명령의 서브 명령

  • create
  • get
  • describe
  • logs
  • delete
  • replace
  • patch
  • apply
  • diff

파드 디자인

  • 단일 컨테이너: 일반 적인 형태
  • 멀티 컨테이너: 메인 애플리케이션이 존재 매인 애플리케이션 기능을 확장 하기 위한 컨테이너를 배치

사이드카 패턴
https://kubernetes.io/blog/2015/06/the-distributed-system-toolkit-patterns/

  • sidecar: 기능의 확장
  • ambassador: 프록시/LB
  • adpator: 출력의 표준

포트 및 포트 포워딩

테스트 & 디버깅 목적

kubectl port-forward pods/myweb 8080:80

이름 & UID

이름: 네임스페이스 유일
UID: 클러스터에서 유일


Namespace

리소스를 분리

  • 서비스 별
  • 사용자 별
  • 환경: 개발, 스테이징, 프로덕션

서비스: DNS 이름이 분리되는 용도
RBAC: 권한을 NS에 설정

https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/namespaces/

kubectl get namespaces
  • kube-system: Kubernetes의 핵심 컴포넌트
  • kube-public: 모든 사용자가 읽기 권한
  • kube-node-lease: 노드의 HeartBeat 체크를 위한 Lease 리소스가 존재
  • default: 기본 작업 공간
    namespace(ns) 생성
kubectl create ns developments

ns 삭제

kubectl delete ns developments

ns 확인

kubectl get pods -A | --all-namespaces

name 옵션을 통한 확인

kubectl get pods -n kube-system

ns-dev.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: dev
kubectl create -f ns-dev.yaml

myweb-dev.yaml

apiVersion: v1
kind: Pod
metadata:
  name: myweb
  namespace: dev
spec:
  containers:
    - name: myweb
      image: httpd
      ports:
        - containerPort: 80
          protocol: TCP          
kubectl create -f myweb-dev.yaml
kubectl delete -f myweb-dev.yaml

Label & LabelSelector

https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/labels/
https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/common-labels/

Label

레이블 확인

kubectl get pods --show-labels
kubectl get pods X -o yaml
kubectl describe pods X

레이블 관리

kubectl label pods myweb APP=apache
kubectl label pods myweb ENV=developments
kubectl label pods myweb ENV=staging

overwrite 옵션 사용 (덮어쓰기)

kubectl label pods myweb ENV=staging --overwirte
kubectl label pods myweb ENV-

LabelSelector

  • 검색
  • 리소스 간 연결

일치성(equality base)

  • =
  • ==
  • !=
kubectl get pods -l APP=nginx
kubectl get pods -l APP==nginx
kubectl get pods -l 'APP!=nginx'

집합성(set base)

  • in
  • notin
  • exists: 키만 매칭
    - kubectl get pods -l 'APP'
  • doesnotexists: 키 제외 매칭
    - kubectl get pods -l '!APP'

Annotations

레이블과 비슷
비 식별 메타데이타
애플리케이션이 해당 메타데이터를 참조할 수 있음 -> 애플리케이션 작동 변경

명령형 커맨드

kubectl annotate pods myweb created-by=Jang
kubectl annotate pods myweb created-by=Kim --overwrite
kubectl annotate pods myweb created-by-

YAML

apiVersion: v1
kind: Pod
metadata:
  name: myweb-label-anno
  labels:
    APP: apache
    ENV: staging
  annotations:
    Created-by: Jang
spec:
  containers:
    - name: myweb
      image: httpd
      ports:
        - containerPort: 80
          protocol: TCP

profile
클라우드신생아

0개의 댓글