Today I Learn - 46

이정빈·2021년 4월 23일
0

클라우드 엔지니어

목록 보기
47/53
post-thumbnail

Kubernetes

Control Plane

API-server

쿠버네티스 서비스의 핵심요소.
모든 쿠버네티스 서비스는 api를 거쳐가기 때문에 이것이 없으면 쿠버네티스 서비스 운영되지 않는다.

etcd

모든 쿠버네티스 클러스터 상태를 저장하고 복제

Scheduler

노드가 배정되지 않은 생성된 파드를 감지하고 노드에 배정해주는 컴포넌트

Kube controller manager

컨트롤러를 구동하는 마스터 상의 컴포넌트.

논리적으로 노드, 레플리케이션, 엔드포인트 , 서비스 어카운트& 토큰을 컨트롤한다.

Kubeadm을 이용한 Kubernetes 설치

Control Plane

컨트롤 플레인 초기화

sudo kubeadm init --apiserver-advertise-address=192.168.200.11 
--pod-network-cidr=192.168.0.0/16

컨테이너 네트워크 애드온 설치(Calico)

kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml

확인

kubectl get nodes
kubectl get pods -A
watch -n1 -d kubectl get pods -A

Node

컨트롤 플레인 노드에서 토큰과 해쉬를 확인하고, kubeadm join을 이용하여 노드에서 값을 입력해야 조인시킬 수 있다.

kubeadm join --token <token> <control-plane-host>:<control-plane-port> --discovery-token-ca-cert-hash sha256:<hash>
  • ```kubeadm token list```
  • :
    kubectl cluster-info

  • <hash>

    openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \
       openssl dgst -sha256 -hex | sed 's/^.* //'
sudo kubeadm join 192.168.200.11:6443 --token tlkf73.smja9l2ks634rpk7 \
    --discovery-token-ca-cert-hash sha256:bd5e8092adeaa81fcf838ab7f8a72d0fe29fcfc8d8af37bfa65e128a4a2350a4

Kubernetes resource

Partition

namespaces
nodes

Workload

  • Pod
  • Controller
    • replicationcontrollers
    • replicasets
    • statefulsets
    • daemonsets
    • deployments
    • cronjobs
    • jobs
    • horizontalpodautoscalers

Network

services
endpoints
ingresses

Storage

persistentvolumeclaims
persistentvolumes
storageclasses

Configuration

configmaps
secrets

Authentication/Authorization

serviceaccounts
clusterrolebindings
clusterroles
rolebindings
roles
certificatesigningrequests

Resource Control

limitranges
resourcequotas

Etc

customresourcedefinitions


API Version

  • Stable
  • Beta: 잘 테스트 되었음/검증되었음(오류 없음), 기능 변경 O(예고, 방법, 대응) - Mission Critical
  • Alpha: 개발 중, 오류가 있을 수 있음, 기능 변경 O(갑자기) (기본 비활성)

Alpha -> Beta -> Stable

v1alpha1

v1alpha2

v1alpha3

v1beta1

v1beta2

v1


kubectl api-resources

kubectl api-versions

kubectl explain

kubectl explain pods.spec --recursive


쿠버네티스 리소스를 YAML 파일 형태 정의

apiVersion:
kind:
metadata:
spec:
apiVersion: v1
kind: Pod
metadata:
  name: web2
spec:
  containers:
  - name: web2
    image: httpd
apiVersion: v1
kind: Pod
metadata:
  name: web3
spec:
  containers:
  - name: web3a
    image: httpd
  - name: web3b
    image: c1t1d0s7/myweb
vi ~/.vimrc
syntax on
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab autoindent

파드 생성

kubectl run web1 --image httpd
kubectl create -f web1-pod.yaml

파드 목록

kubectl get pods
kubectl get pods -o wide

파드 상세 정보

kubectl describe pod web1
kubectl get pod web1 -o yaml

파드의 로그 확인

kubectl logs web1

파드의 포트 포워드

kubectl port-forward pod/web1 80:80
curl localhost

파드 삭제

kubectl delete pod web1
kubectl delete -f web1-pod.yaml
profile
WAS Engineer, Cloud Engineer(지망)

0개의 댓글