Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[week2 tmi] ETCD 데이터 조회 실습 #17

Open
ur2e opened this issue Sep 27, 2023 · 0 comments
Open

[week2 tmi] ETCD 데이터 조회 실습 #17

ur2e opened this issue Sep 27, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@ur2e
Copy link
Collaborator

ur2e commented Sep 27, 2023

ETCD = A distributed, reliable key-value store for the most critical data of a distributed system.

kubectl get [k8s object]) 명령을 사용할 때 얻는 정보는 etcd로 부터 받는 정보입니다.
임의의 파드를 생성한 후, etcd에 저장된 pod 정보를 확인해보는 간단한 실습을 진행하였습니다.

# etcd 설치
sudo apt-get -y update && sudo apt-get -y install etcd-client

# 버전 확인
yji@k8s-master:~$ etcdctl version
etcdctl version: 3.2.26
API version: 3.2

-----------------------------------------------------------------------------------------------
/*
 * 📕 실습. pod 생성 후 etcd에 저장된 파드 정보 확인하기
 */ 

💻 master 1 
# nginx-m2라는 이름의 pod 생성
$ kubectl run nginx --image=nginx-m2

# etcd를 조회하기위해 관리자 모드로 변경 
$ su -

# etcd에 저장된 데이터들을 알아보기위해 etcd3ctl get 명령을 json 확장자 파일로 redirect
$ etcd3ctl get / --prefix=true -w json > etcd_data.json

# jq 패키지를 사용해서 정렬되지 않은 json 파일을 포맷팅 한다. 
$ jq '.' etcd_data.json

		- jq 패키지 실행 전 etcd_data.json
		{"header":{"cluster_id":15516845868796936735,"member_id":11051356363797606022,"revision":517184,"raft_term":12},"kvs":[{"key":"L3JlZ2lzdHJ5L2FwaWV4dGVuc2lvbnMuazhzLmlvL2N1c3RvbXJlc291cmNlZGVmaW5pdGlvbnMvYmdwY29uZmlndXJhdGlvbnMuY3JkLnByb2plY3RjYWxpY28ub3Jn","create_revision":7146,"mod_revision":7150,"version":3,"value":"eyJraW5kIjoiQ3VzdG9tUmVzb3VyY2VEZWZpbml0aW9uIiwiYXBpVmVyc2lvbiI6ImFwaWV4dGVuc2lvbnMuazhzLmlvL3YxYmV0YTEiLCJtZXRhZGF0YSI6eyJuYW1lIjoiYmdwY29uZmlndXJhdGlvbnMuY3JkLnByb2plY3RjYWxpY28ub3JnIiwidWlkIjoiZjI5NmI0YmEtOTdmMy00ZDJiLWIzY2MtOTc0MmJmY2VjM2UyIiwiZ2VuZXJhdGlvbiI6MSwiY3JlYXRpb25UaW1lc3RhbXAiOiIyMDIyLTEwLTA3VDExOjMyOjQ2WiIsImFubm90YXRpb25zIjp7Imt1YmVjdGwua3ViZXJuZXRlcy5pby9sYXN0LWFwcGxpZWQtY29uZmlndXJhdGlvbiI6IntcImFwaVZlcnNpb25cIjpcImFwaWV4dGVuc2lvbnMuazhzLmlvL3YxXCIsXCJraW5kXCI6XCJDdXN0b21SZXNvdXJjZURlZmluaXRpb25cIixcIm1ldGFkYXRhXCI6e1wiYW5ub3RhdGlvbnNcIjp7fSxcIm5hbWVcIjpcImJncGNvbmZpZ3VyYXRpb25zLmNyZC5wcm9qZWN0Y2FsaWNvLm9yZ1wifSxcInNwZWNcIjp7XCJncm91cFwiOlwiY3JkLnByb2plY3RjYWxpY28ub3JnXCIsXCJuYW1lc1wiOntcImt
		json...}}}}
		

		- jq 패키지 실행 후 etcd_data.json // etcd는 key-value 형태의 스토리지임을 확인할 수 있음
		{
		  "header": {
		    "cluster_id": 15516845868796936000,
		    "member_id": 11051356363797606000,
		    "revision": 517184,
		    "raft_term": 12
		  },
		  "kvs": [
		    {
		      "key": "L3JlZ2lzdHJ5L2FwaWV4dGVuc2lvbnMuazhzLmlvL2N1c3RvbXJlc291cmNlZGVmaW5pdGlvbnMvYmdwY29uZmlndXJhdGlvbnMuY3JkLnByb2plY3RjYWxpY28ub3Jn",
		      "create_revision": 7146,
		      "mod_revision": 7150,
		      "version": 3,
		      "value": "eyJraW5kIjoiQ3VzdG9tUmVzb3VyY2VEZWZpbml0aW9uIiwiYXBpVmVyc2lvbiI6ImFwaWV4dGVuc2lvbnMuazhzLmlvL3YxYmV0YT

# key 값 디코딩하여 etcd에 저장된 데이터를 확인
	# jq '.kvs[].key' : jq로 원하는 kvs키의 value 값
  # cut -d '"' -f2: "(쌍따옴표)를 구분자로 2째 필드값을 자르기
  #  base64 --decode: base64-decoding
$ for k in $(cat etcd_data.json | jq '.kvs[].key' | cut -d '"' -f2); do echo $k | base64 --decode; echo; done > etcd-data.txt

# 디코딩된 값 조회 
$ vi etcd-data.txt 
/registry/csinodes/k8s-master-1
/registry/csinodes/k8s-master-2
/registry/csinodes/k8s-master-3
/registry/daemonsets/kube-system/calico-node
/registry/daemonsets/kube-system/kube-proxy
/registry/daemonsets/monitoring/node-exporter
/registry/pods/default/nginx-m1
/registry/pods/default/nginx-m2   # 아까 생성한 파드 nginx-m2가 저장


# 아까 생성한 pod를 etcdctl 명령으로 조회하여 etcd가 저장한 pod의 정보를 조회 
# 문자열 데이터가 아닌 부분은 깨져있다.
$ etcd3ctl get /registry/pods/default/nginx-m2 > etcd-nginx-m2
^Bv1^R^Rmetadata.namespace^P¤^C^R<91>^A
^H🟣nginx-m2^R^Enginx*^@B^@JL
^Ukube-api-access-hvvvg^P^A^Z-/var/run/secrets/kubernetes.io/serviceaccount"^@2^@j^T/dev/termination-logr^FAlways<80>^A^@<88>^A^@<90>^A^@¢^A^DFile^Z^FAlways ^^2^LClusterFirstB^GdefaultJ^GdefaultR^Lk8s-worker-3X^@`^@h^@r^@<82>^A^@<8a>^A^@<9a>^A^Qdefault-scheduler²^A6
^G🟢Running^R#
^KInitialized^R^DTrue^Z^@"^H^Håã<93><9a>^F^P^@*^@2^@^R^]
^EReady^R^DTrue^Z^@"^H^Héã<93><9a>^F^P^@*^@2^@^R'
^OContainersReady^R^DTrue^Z^@"^H^Héã<93><9a>^F^P^@*^@2^@^R$
^LPodScheduled^R^DTrue^Z^@"^H^H<81>ô<93><9a>^F^P^@*^@2^@^Z^@"^@*^N192.168.56.2032^L10.98.69.216:^H^Håã<93><9a>^F^P^@Bð^A
^Hnginx-m2^R^L^R

^H^Héã<93><9a>^F^P^@^Z^@ ^A(^@2^^🔴docker.io/library/nginx:latest:_docker.io/library/nginx@sha256:2f770d2fe27bc85f68fd7fe6a63900ef7076bc703022fe81b980377fe3d27b70M⚫containerd://6ff1306a4f878d831b6530f3a789ed0e4f00ec50962c698814fbffd12b841376H^AJ
BestEffortZ^@b^N
^L🟡10.98.69.216^Z^@"^@

# 아까 생성한 nginx-m pod의 상세 정보 조회 > etcd가 저장한 pod의 정보와 유사한 부분들을 확인할 수 있음
$ kubectl describe po nginx-m2
Name:         🟣nginx-m2
Namespace:    default
Status:       🟢Running
IP:           10.98.69.216
IPs:
  IP:  🟡10.98.69.216
Containers:
  nginx-m2:
    Container ID:   ⚫containerd://6ff1306a4f878d831b6530f3a789ed0e4f00ec50962c698814fbffd12b841376
    Image:          nginx
    Image ID:       🔴docker.io/library/nginx@sha256:2f770d2fe27bc85f68fd7fe6a63900ef7076bc703022fe81b980377fe3d27b70
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Tue, 11 Oct 2022 13:32:41 +0900
    Ready:          True
@ur2e ur2e added the documentation Improvements or additions to documentation label Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant