Today I Learn - 47

이정빈·2021년 4월 26일
0

클라우드 엔지니어

목록 보기
48/53
post-thumbnail

Kubespray

https://github.com/kubernetes-sigs/kubespray

  • kubespray를 받을 수 있는 깃허브 주소

https://kubernetes.io/ko/docs/setup/production-environment/tools/kubespray/

  • 쿠버스프레이에 대해 설명한 공식 문서

kubespray 받기

git clone --branch release-2.14 https://github.com/kubernetes-sigs/kubespray.git
  • 도커가 설치되어있어야 한다.
cd kubespray

사전 요구사항 설치

sudo apt install python3-pip
sudo pip3 install -r requirements.txt

SSH 키 인증 구성

ssh-keygen
ssh-copy-id vagrant@192.168.201.11
ssh-copy-id vagrant@192.168.201.21
ssh-copy-id vagrant@192.168.201.22
ssh-copy-id vagrant@192.168.201.23
  • 워커노드에 접속시 비밀번호를 요구하기 때문에 키를 생성하여 등록해줌으로써 그 과정을 생략 한다.

인벤토리 구성

cp -r inventory/sample inventory/mycluster

-ansidble로 구성되기 때문에 인벤토리의 설정을 구성해야한다. 사전제공된 인벤토리를 자신의 디렉토리를 만들어 복사한다.

vi inventory/mycluster/inventory.ini
  • 인벤토리 파일을 vi편집기를 통해 설정한다.
[all]
k8s-m1 ansible_host=192.168.201.11 ip=192.168.201.11 ansible_connection=local
k8s-w1 ansible_host=192.168.201.21 ip=192.168.201.21
k8s-w2 ansible_host=192.168.201.22 ip=192.168.201.22
k8s-w3 ansible_host=192.168.201.23 ip=192.168.201.23

[kube-master]
k8s-m1

[etcd]
k8s-m1

[kube-node]
k8s-w1
k8s-w2
k8s-w3

[calico-rr]

[k8s-cluster:children]
kube-master
kube-node
calico-rr
  • inventory.ini 파일안에 설정할 내용.

쿠버네티스 배포/플레이북 실행

ansible all -i inventory/mycluster/inventory.ini -m ping
  • ansible로 마스터 노드와 워커 노드가 잘 통신이 되는지 점검.
ansible-playbook -i inventory/mycluster/inventory.ini cl
uster.yml -b

-ansible playbook을 실행하여 쿠버네티스를 배포한다.

kubeconfig 파일 복사

mkdir $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubectl 자동완성 기능

kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl
exec bash

  • 쿠버네티스가 제대로 설치되었는지 체크한다.
kubectl run test -it --rm --image=ubuntu
kubectl exec -it web-pod -c httpd1 bash
kubectl run
kubectl create
kubectl get
kubectl get -o wide
kubectl get -o yaml
kubectl describe
kubectl logs (-c)
kubectl port-forward (-c)
kubectl exec (-c)
kubectl delete

Pod

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
spec:
  containers:
  - name: myapp
    image: ghcr.io/c1t1d0s7/go-myweb
    ports:
    - containerPort: 8080
      protocol: TCP

레이블

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

  • 검색
  • 리소스 간 연결
...
metadata:
  name: myapp-pod
  labels:
    app: myapp
    env: development
    ...
kubectl label pod web1 app=httpd
kubectl label pod web1 app=myapp --overwrite
kubectl label pod web1 app='' --overwrite
kubectl label pod web1 app-

레이블 확인

kubectl get pods --show-labels
kubectl get pod myapp-pod -o yaml
kubectl describe pod myapp-pod

레이블 셀렉터

kubectl get -l <EXPR>
일치성(Equality Based)
  • Key =Value
  • Key == Value
  • Key != Value
집합성(Set Based)
  • Key in (Value)
  • Key notin (Value)
  • Key
  • !Key

Annotations

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

kubectl annotate pod web1 header=jang
kubectl annotate pod web1 header=kim --overwrite
kubectl annotate pod web1 header-
metadata:
  name: myapp-pod
  labels:
    app: myapp
    env: development
  annotations:
    header: jang
    ...
  • Label: 식별
  • Annotation: 비-식별 정보 (API 또는 라이브러리를 통해 해당 값을 참조)

Namespace

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

kubectl -n | --namespace
metadata:
  name: myapp-pod
  namespace: kube-system
kubectl create namespace quality-assurance
apiVersion: v1
kind: Namespace
metadata:
  name: quality-assurance

Pod Lifecycle

https://kubernetes.io/ko/docs/concepts/workloads/pods/pod-lifecycle/

파드의 단계

  • Pending
  • Running
  • Succeeded
  • Failed
  • Unknown
  • Terminating

컨테이너의 상태

  • Waiting
  • Running
  • Terminated

Replication Controller(rc)

https://kubernetes.io/ko/docs/concepts/workloads/controllers/replicationcontroller/

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
  • .spec.replicas: 복제본 개수(기본: 1)

  • .spec.selector: 파드 레이블 셀렉터

  • .spec.template: 파드 템플릿

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80

파드, 레이블, 셀렉터, 레플리케이션 컨트롤러의 설명은... 너무 어렵다. 혼자서 더 복습해봐야 겠다.

profile
WAS Engineer, Cloud Engineer(지망)

0개의 댓글