Skip to content

Instantly share code, notes, and snippets.

@ianychoi
Last active July 31, 2021 15:02
Show Gist options
  • Save ianychoi/07c2957df210c8de8d58de0992081cb1 to your computer and use it in GitHub Desktop.
Save ianychoi/07c2957df210c8de8d58de0992081cb1 to your computer and use it in GitHub Desktop.
쿠버네티스 - MSA 앱 배포 (YAOBank) 실습
# 생성
curl -s -O https://raw.githubusercontent.com/tigera/ccol1/main/yaobank.yaml
sed -i 's/nodeSelector/#nodeSelector/g' yaobank.yaml && sed -i 's/kubernetes.io/#kubernetes.io/g' yaobank.yaml
kubectl apply -f yaobank.yaml

# 네임스페이스 변경
kubens yaobank

# 확인
kubectl get all
[root@k8s-m:~ (K8S:yaobank)]# kubectl get all
NAME                            READY   STATUS    RESTARTS   AGE
pod/customer-68d67b588d-l79tc   1/1     Running   0          6m59s
pod/database-899b4f58f-vjxgv    1/1     Running   0          6m59s
pod/summary-748b977d44-k47zw    1/1     Running   0          6m59s
pod/summary-748b977d44-pls6q    1/1     Running   0          6m59s

NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/customer   NodePort    10.104.149.17   <none>        80:30180/TCP   6m59s
service/database   ClusterIP   10.101.28.129   <none>        2379/TCP       7m
service/summary    ClusterIP   10.97.223.187   <none>        80/TCP         7m

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/customer   1/1     1            1           6m59s
deployment.apps/database   1/1     1            1           7m
deployment.apps/summary    2/2     2            2           6m59s

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/customer-68d67b588d   1         1         1       6m59s
replicaset.apps/database-899b4f58f    1         1         1       7m
replicaset.apps/summary-748b977d44    2         2         2       6m59s

# customer 파드 웹 접속 확인
curl <customer 파드 IP>
혹은
curl <노드IP>:<NodePort>

# Ubuntu 기반인 경우
apt install -y lynx
# CentOS 기반인 경우에는 아래를 대신 실행하자 (# 제외)
# yum install -y lynx

lynx -dump <노드IP>:<NodePort>
[root@k8s-m:~ (K8S:yaobank)]# lynx -dump 192.168.100.10:30180
                              Welcome to YAO Bank
Name: Spike Curtis
Balance: 2389.45
   [1]Log Out >>
References
   1. http://192.168.100.10:30180/logout

# customer 파드 Shell 접속 후 데이터베이스(etcd) 파드 접속 확인
CUSTOMER_POD=$(kubectl get pods -n yaobank -l app=customer -o name)
kubectl exec -it $CUSTOMER_POD -n yaobank -c customer -- /bin/bash
-----------------------------------------
curl -s http://database:2379/v2/keys?recursive=true | python -m json.tool
exit
-----------------------------------------

# 혹은 직접 데이터베이스(etcd) 파드 접속 확인
# 출력 내용을 https://jsonformatter.curiousconcept.com 붙어녛고 확인
curl -s <database 파드 IP>:2379/v2/keys?recursive=true
curl -s 172.16.197.2:2379/v2/keys
curl -s 172.16.197.2:2379/v2/keys | python3 -m json.tool
curl -s 172.16.197.2:2379/v2/keys?recursive=true
curl -s 172.16.197.2:2379/v2/keys?recursive=true | python3 -m json.tool
[root@k8s-m:~ (K8S:yaobank)]# curl -s 172.16.197.2:2379/v2/keys?recursive=true
{"action":"get","node":{"dir":true,"nodes":[{"key":"/accounts","dir":true,"nodes":[{"key":"/accounts/036273","dir":true,"nodes":[{"key":"/accounts/036273/name","value":"Sally Yates","modifiedIndex":13,"createdIndex":13},{"key":"/accounts/036273/balance","value":"3597.89","modifiedIndex":14,"createdIndex":14}],"modifiedIndex":13,"createdIndex":13},{"key":"/accounts/468009","dir":true,"nodes":[{"key":"/accounts/468009/name","value":"Laura Sargent","modifiedIndex":15,"createdIndex":15},{"key":"/accounts/468009/balance","value":"8854.39","modifiedIndex":16,"createdIndex":16}],"modifiedIndex":15,"createdIndex":15},{"key":"/accounts/519940","dir":true,"nodes":[{"key":"/accounts/519940/name","value":"Spike Curtis","modifiedIndex":5,"createdIndex":5},{"key":"/accounts/519940/balance","value":"2389.45","modifiedIndex":6,"createdIndex":6}],"modifiedIndex":5,"createdIndex":5},{"key":"/accounts/407221","dir":true,"nodes":[{"key":"/accounts/407221/name","value":"Simon Gideon","modifiedIndex":7,"createdIndex":7},{"key":"/accounts/407221/balance","value":"95780.11","modifiedIndex":8,"createdIndex":8}],"modifiedIndex":7,"createdIndex":7},{"key":"/accounts/387747","dir":true,"nodes":[{"key":"/accounts/387747/balance","value":"39082.11","modifiedIndex":10,"createdIndex":10},{"key":"/accounts/387747/name","value":"Harry Norman Kynes","modifiedIndex":9,"createdIndex":9}],"modifiedIndex":9,"createdIndex":9},{"key":"/accounts/436839","dir":true,"nodes":[{"key":"/accounts/436839/name","value":"George Ball","modifiedIndex":11,"createdIndex":11},{"key":"/accounts/436839/balance","value":"543.34","modifiedIndex":12,"createdIndex":12}],"modifiedIndex":11,"createdIndex":11}],"modifiedIndex":5,"createdIndex":5}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment