[kubernetes] API서버와 etcd 정보 일치 확인

DaeHoon·2022년 9월 12일
0

kubernetes

목록 보기
6/6

API 서버와 ETCD

  • 쿠버네티스는 저장되어 있는 정보를 다루기 위해 etcdclt 제공한다.

API 서버의 정보가 etcd로 업데이트 되는지 확인

- etcdctl install
[root@m-k8s ~]# ~/_Lecture_k8s_starter.kit/ch8/003/install_etcdctl.sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16.7M  100 16.7M    0     0  3849k      0  0:00:04  0:00:04 --:--:-- 3850k
etcdctl successfully installed

- shell 내용
[root@m-k8s ~]# cat ~/_Lecture_k8s_starter.kit/ch8/003/install_etcdctl.sh 
#!/usr/bin/env bash

curl https://raw.githubusercontent.com/sysnet4admin/BB/main/etcdctl/v3.4.15/etcdctl -o /usr/local/bin/etcdctl
chmod +x /usr/local/bin/etcdctl
echo "etcdctl successfully installed"
  • 강의 자료에 있는 sh 파일을 통해 다운 받는다.
[root@m-k8s ~]# cat _Lecture_k8s_starter.kit/ch8/003/.cmd
ETCDCTL_API=3 etcdctl --endpoints=https://[192.168.1.10]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key get --prefix=true "" > /tmp/prefix

cat /tmp/prefix | nl | tail 
cat /tmp/prefix | nl | grep -i 'pod":"sysnet4admin'
  • ETCD에 접속을 해 모든 정보를 가져온 뒤, tmp/prefix에 저장하는 명령어
[root@m-k8s ~]# kubectl apply -f _Lecture_k8s_starter.kit/ch8/003/sysnet4admin.yaml 
deployment.apps/sysnet4admin created
  • sysnet4admin 디플로이먼트를 만들어 API 서버와 etcd 정보가 일치하는지 확인해보자.
- ETCD에 접속을 해 모든 정보를 가져온 뒤, tmp/prefix에 저장
[root@m-k8s ~]# ETCDCTL_API=3 etcdctl --endpoints=https://[192.168.1.10]:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key get --prefix=true "" > /tmp/prefix

- 3개의 파드가 배포되어, 3개의 sysnet4admin 파드 정보를 볼 수 있다.

[root@m-k8s ~]# cat /tmp/prefix | nl | grep -i 'pod":"sysnet4admin'
  2751  {"apiVersion":"crd.projectcalico.org/v1","kind":"IPAMBlock","metadata":{"annotations":{"projectcalico.org/metadata":"{\"creationTimestamp\":null}"},"creationTimestamp":"2022-08-21T04:37:34Z","generation":34,"managedFields":[{"apiVersion":"crd.projectcalico.org/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:projectcalico.org/metadata":{}}},"f:spec":{".":{},"f:affinity":{},"f:allocations":{},"f:attributes":{},"f:cidr":{},"f:deleted":{},"f:strictAffinity":{},"f:unallocated":{}}},"manager":"Go-http-client","operation":"Update","time":"2022-08-21T04:37:34Z"}],"name":"172-16-103-128-26","uid":"89c8d0cd-c555-4f58-b19a-56b68d75bf4c"},"spec":{"affinity":"host:w2-k8s","allocations":[0,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"attributes":[{"handle_id":"ipip-tunnel-addr-w2-k8s","secondary":{"node":"w2-k8s","type":"ipipTunnelAddress"}},{"handle_id":"k8s-pod-network.f74ef202bc57b4aa83a4f8b8a15428ca50ab09e7c2849b61c13851dd23d08640","secondary":{"namespace":"kube-system","node":"w2-k8s","pod":"coredns-74ff55c5b-fwl9m"}},{"handle_id":"k8s-pod-network.a406e253651ffa874a5b3095b06db95ace9db36c2ebb1f164da243eda031666c","secondary":{"namespace":"default","node":"w2-k8s","pod":"sysnet4admin-84fb4ff47c-tngzp"}}],"cidr":"172.16.103.128/26","deleted":false,"strictAffinity":false,"unallocated":[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,2,3,1,4,5,6,8,7,9,14,11,12,10,15,16]}}
  2753  {"apiVersion":"crd.projectcalico.org/v1","kind":"IPAMBlock","metadata":{"annotations":{"projectcalico.org/metadata":"{\"creationTimestamp\":null}"},"creationTimestamp":"2022-08-21T04:40:52Z","generation":32,"managedFields":[{"apiVersion":"crd.projectcalico.org/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:projectcalico.org/metadata":{}}},"f:spec":{".":{},"f:affinity":{},"f:allocations":{},"f:attributes":{},"f:cidr":{},"f:deleted":{},"f:strictAffinity":{},"f:unallocated":{}}},"manager":"Go-http-client","operation":"Update","time":"2022-08-21T04:40:52Z"}],"name":"172-16-132-0-26","uid":"0e13e75f-4b12-48b9-b763-cfea228350b8"},"spec":{"affinity":"host:w3-k8s","allocations":[0,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"attributes":[{"handle_id":"ipip-tunnel-addr-w3-k8s","secondary":{"node":"w3-k8s","type":"ipipTunnelAddress"}},{"handle_id":"k8s-pod-network.be1c763f1ac777aee3e84f2a59b8a8b7a31346e4bd8f498c10fa0439d1edf30f","secondary":{"namespace":"kube-system","node":"w3-k8s","pod":"calico-kube-controllers-744cfdf676-tqrbp"}},{"handle_id":"k8s-pod-network.5fd5363b63c1088b26e699fb4e3e629fabbd45901f772ed33a07e67e2cf15103","secondary":{"namespace":"default","node":"w3-k8s","pod":"sysnet4admin-84fb4ff47c-nn7lc"}}],"cidr":"172.16.132.0/26","deleted":false,"strictAffinity":false,"unallocated":[17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,3,1,2,4,6,5,7,8,13,11,9,10,14,15]}}
  2757  {"apiVersion":"crd.projectcalico.org/v1","kind":"IPAMBlock","metadata":{"annotations":{"projectcalico.org/metadata":"{\"creationTimestamp\":null}"},"creationTimestamp":"2022-08-21T04:34:41Z","generation":38,"managedFields":[{"apiVersion":"crd.projectcalico.org/v1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:projectcalico.org/metadata":{}}},"f:spec":{".":{},"f:affinity":{},"f:allocations":{},"f:attributes":{},"f:cidr":{},"f:deleted":{},"f:strictAffinity":{},"f:unallocated":{}}},"manager":"Go-http-client","operation":"Update","time":"2022-08-21T04:34:41Z"}],"name":"172-16-221-128-26","uid":"8c0c183f-b87e-46ff-a23a-2ebc832e3aa7"},"spec":{"affinity":"host:w1-k8s","allocations":[0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"attributes":[{"handle_id":"ipip-tunnel-addr-w1-k8s","secondary":{"node":"w1-k8s","type":"ipipTunnelAddress"}},{"handle_id":"k8s-pod-network.2b13095b92906aaea128305580ddd25393ec22280d3ab247f10af1fe3b84db4a","secondary":{"namespace":"kube-system","node":"w1-k8s","pod":"coredns-74ff55c5b-sh4b7"}},{"handle_id":"k8s-pod-network.92be16c57c6140ed83599b0630ce430808a8d08b76c1f5e3ab708ca9a01e1630","secondary":{"namespace":"default","node":"w1-k8s","pod":"sysnet4admin-84fb4ff47c-hdshh"}}],"cidr":"172.16.221.128/26","deleted":false,"strictAffinity":false,"unallocated":[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,1,2,5,4,3,6,7,8,9,10,14,16,13,11,12,17,18]}}
  • scale 명령을 통해 레플리카를 6개로 늘리면 6개의 정보가 존재
  • 이를 통해 API 서버와 etcd가 싱크가 된다는 것이 증명
profile
평범한 백엔드 개발자

0개의 댓글