API-server
쿠버네티스 서비스의 핵심요소.
모든 쿠버네티스 서비스는 api를 거쳐가기 때문에 이것이 없으면 쿠버네티스 서비스 운영되지 않는다.
etcd
모든 쿠버네티스 클러스터 상태를 저장하고 복제
Scheduler
노드가 배정되지 않은 생성된 파드를 감지하고 노드에 배정해주는 컴포넌트
Kube controller manager
컨트롤러를 구동하는 마스터 상의 컴포넌트.
논리적으로 노드, 레플리케이션, 엔드포인트 , 서비스 어카운트& 토큰을 컨트롤한다.
컨트롤 플레인 초기화
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
컨트롤 플레인 노드에서 토큰과 해쉬를 확인하고, kubeadm join을 이용하여 노드에서 값을 입력해야 조인시킬 수 있다.
kubeadm join --token <token> <control-plane-host>:<control-plane-port> --discovery-token-ca-cert-hash sha256:<hash>
:
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
namespaces
nodes
services
endpoints
ingresses
persistentvolumeclaims
persistentvolumes
storageclasses
configmaps
secrets
serviceaccounts
clusterrolebindings
clusterroles
rolebindings
roles
certificatesigningrequests
limitranges
resourcequotas
customresourcedefinitions
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