1. 쿠버네티스 6. kops로 k8s 클러스터 생성(필수) aws configure kubectl version --client=true -o yaml | yh kops version aws --version REGION=ap-northeast-2 aws s3 mb s3://agame-bk1 --region $REGION export AWS_PAGER="" export REGION=ap-northeast-2 export KOPS_CLUSTER_NAME=ai-002.click export KOPS_STATE_STORE=s3://agame-bk1 echo 'export AWS_PAGER=""' >>~/.bashrc echo 'export REGION=ap-northeast-2' >>~/.bashrc echo 'export KOPS_CLUSTER_NAME=ai-002.click' >>~/.bashrc echo 'export KOPS_STATE_STORE=s3://agame-bk1' >>~/.bashrc echo $REGION echo $KOPS_CLUSTER_NAME echo $KOPS_STATE_STORE 9 생성 (30분) kops create cluster --zones="$REGION"a,"$REGION"c --networking amazonvpc --cloud aws --control-plane-size t3.medium --node-size t3.medium --node-count=2 --network-cidr 172.30.0.0/16 --ssh-public-key ~/.ssh/id_rsa.pub --name=$KOPS_CLUSTER_NAME --kubernetes-version "1.32.0" -y 12 혹, 생성을 잘못 했다면 지우고 다시 생성 kops delete cluster --yes 1) [새 터미널1] Kops로 쿠버네티스 생성시 EC2 생성 모니터링 while true; do aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIPAdd:PublicIpAddress,InstanceName:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters Name=instance-state-name,Values=running --output text ; echo "------------------------------" ; sleep 1; done 결과 ------------------------------ nodes-ap-northeast-2c.ai-002.click 13.125.130.66 running kops-ec2 54.180.132.142 running nodes-ap-northeast-2a.ai-002.click 43.203.121.219 running control-plane-ap-northeast-2a.masters.ai-002.click 13.125.134.195 running 2) while true; do kubectl get nodes ; echo "------------------------------" ; sleep 2; done ------------------ NAME STATUS ROLES AGE VERSION i-052941dff8ad3ff52 Ready node 12m v1.34.0 i-099f8ed8d6df35870 Ready control-plane 14m v1.34.0 i-0fb8a7b63596070ae NotReady node 12m v1.34.0 ------------------ NAME STATUS ROLES AGE VERSION i-0189330e1f99dfe71 Ready node 34s v1.32.0 i-0ae2d9f1ae5f6a22b Ready node 37s v1.32.0 i-0ca76c17a7f43cb83 Ready control-plane 2m27s v1.32.0 ------------------ while true; do k get no ; echo "------------------"; date; sleep 2 ; done node와 컨트롤 플래인 1대가 생성되었다!!!! while true; do kubectl get nodes --show-labels ; echo "------------------------------" ; sleep 2; done --------------- 9. 디플로이먼트 배포 cat < W2PIP=<워커 노드 2 Public IP> W1PIP=52.79.243.223 W2PIP=3.39.229.222 5 # 워커 노드 스토리지 확인 ssh -i ~/.ssh/id_rsa ubuntu@$W1PIP df -hT -t ext4 Filesystem Type Size Used Avail Use% Mounted on /dev/root ext4 123G 5.2G 118G 5% / /dev/nvme0n1p16 ext4 881M 89M 730M 11% /boot ssh -i ~/.ssh/id_rsa ubuntu@$W2PIP df -hT -t ext4 Filesystem Type Size Used Avail Use% Mounted on /dev/root ext4 123G 2.8G 121G 3% / /dev/nvme0n1p16 ext4 881M 89M 730M 11% /boot 6 # 노드2에 디스크에 큰 파일 생성 ssh -i ~/.ssh/id_rsa ubuntu@$W2PIP fallocate -l 110g 110g-file 7 # 노드2에 디스크에 용량 확인 >> 90% 넘김! ssh -i ~/.ssh/id_rsa ubuntu@$W2PIP df -hT -t ext4 Filesystem Type Size Used Avail Use% Mounted on /dev/root ext4 124G 114G 11G 92% / 8 # 파드 상태 확인 >> 노드2에서 쫓겨남 확인! 모니터링 상태 NAME READY STATUS RESTARTS AGE pod/busybox-6b5c698b45-4xzbm 0/1 Error 0 27m pod/busybox-6b5c698b45-7km8j 1/1 Running 0 27m pod/busybox-6b5c698b45-chxvl 1/1 Running 0 4s pod/busybox-6b5c698b45-ggmjw 1/1 Running 0 27m pod/busybox-6b5c698b45-jtd26 0/1 Error 0 27m pod/busybox-6b5c698b45-m6s8t 1/1 Running 0 35s pod/busybox-6b5c698b45-nbcd4 1/1 Running 0 27m pod/busybox-6b5c698b45-ncdps 0/1 Error 0 27m pod/busybox-6b5c698b45-x5t24 1/1 Running 0 66s kubectl get pod –owide (ai-002:my-webs) [root@kops-ec2 ~]# kubectl get pod -owide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES busybox-74d4c7fb8c-4j4nd 1/1 Running 0 6m46s 172.30.160.34 i-0f0384f73ed4e1d86 busybox-74d4c7fb8c-6678w 1/1 Running 0 6m46s 172.30.154.201 i-0f0384f73ed4e1d86 busybox-74d4c7fb8c-6gxpf 1/1 Running 0 6m46s 172.30.225.86 i-0f0384f73ed4e1d86 busybox-74d4c7fb8c-7tdfp 1/1 Running 0 6m46s 172.30.235.87 i-0f0384f73ed4e1d86 busybox-74d4c7fb8c-qkwx2 1/1 Running 0 6m46s 172.30.216.106 i-0f0384f73ed4e1d86 busybox-74d4c7fb8c-v89pc 1/1 Running 0 6m46s 172.30.152.245 i-0f0384f73ed4e1d86 (ai-002:my-webs) [root@kops-ec2 ~]# 9 # 노드의 이벤트이므로 클러스터 이벤트 확인 kubectl get events collect required amount of images. Wanted to free 4255717785 bytes, but freed 0 bytes 11m Warning FreeDiskSpaceFailed node/k8s-n2 failed to garbage collect required amount of images. Wanted to free 4258220441 bytes, but freed 0 bytes 6m46s Warning FreeDiskSpaceFailed node/k8s-n2 failed to garbage kubectl describe nodes 0s Warning EvictionThresholdMet node/i-0c570795ec5b1f7a1 Attempting to reclaim ephemeral-storage 0s Warning EvictionThresholdMet node/i-0c570795ec5b1f7a1 Attempting to reclaim ephemeral-storage 0s Warning EvictionThresholdMet node/i-0c570795ec5b1f7a1 Attempting to reclaim ephemeral-storage 확인까지만 ~~~ 10 # 삭제 kubectl delete deploy busybox ssh -i ~/.ssh/id_rsa ubuntu@$W2PIP rm -rf 110g-file ------------------------- 13. Helm [등록] helm repo add bitnami https://charts.bitnami.com/bitnami [조회] helm repo list NAME URL bitnami https://charts.bitnami.com/bitnami [Chart 찾기] helm search repo bitnami | grep tomcat bitnami/tomcat 13.3.0 11.0.15 Apache Tomcat is an open-source web server desi... [업데이트] helm repo update [삭제] helm repo remove bitnami # [Tomcat 배포] 현재 Chart 최신 버전 helm install my-tomcat bitnami/tomcat helm install my-tomcat2 bitnami/tomcat --version 9.6.3 --set persistence.enabled=false 5 # 삭제 ? [릴리즈 조회] helm list [릴리즈 배포 상태확인] - 처음 배포 시 설명도 출력 helm status my-tomcat [릴리즈 삭제] helm uninstall my-tomcat helm uninstall my-tomcat2 [Pod 확인] kubectl get pods No resources found in my-webs namespace. ------------- 14. 노드 최대 파드 배포 이해 워커 노드의 인스턴스 타입 별 파드 생성 갯수 제한이 있다. 참고해서 배포 해야 한다. 1 # t3 타입의 정보(필터) 확인 aws ec2 describe-instance-types --filters Name=instance-type,Values=t3.* --query "InstanceTypes[].{Type: InstanceType, MaxENI: NetworkInfo.MaximumNetworkInterfaces, IPv4addr: NetworkInfo.Ipv4AddressesPerInterface}" --output table 2 # 워커노드 상세 정보 확인 : 노드 상세 정보의 Allocatable 에 pods 에 17개 정보 확인 kubectl describe node | grep Allocatable: -A6 Allocatable: cpu: 2 ephemeral-storage: 59763732382 hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 3854320Ki pods: 17 3 # 워커 노드 접속 ,Public IP 확인 aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIPAdd:PublicIpAddress,InstanceName:Tags[?Key=='Name']|[0].Value}" --filters Name=instance-state-name,Values=running --output table W1PIP=52.79.243.223 W2PIP=3.39.229.222 ssh -i ~/.ssh/id_rsa ubuntu@$W1PIP ubuntu@i-0f0384f73ed4e1d86:~$ # 워커 노드 EC2 - 모니터링 watch -d "ip link | egrep 'ens|eni'" while true; do ip -br -c addr show && echo "--------------" ; date "+%Y-%m-%d %H:%M:%S" ; sleep 2; done 4 # 작업용 EC2 - 터미널1 watch -d 'kubectl get pods -o wide' 5 # 작업용 EC2 - 터미널2 # 디플로이먼트 생성 kubectl apply -f https://raw.githubusercontent.com/gasida/PKOS/main/2/nginx-dp.yaml # 파드 확인 kubectl get pod -o wide kubectl get pod -o=custom-columns=NAME:.metadata.name,IP:.status.podIP kubectl ktop 6 # 파드 증가 테스트 >> 파드 정상 생성 확인, 워커 노드에서 eth, eni 갯수 확인 kubectl scale deployment nginx-deployment --replicas=8 # 파드 증가 테스트 >> 파드 정상 생성 확인, 워커 노드에서 eth, eni 갯수 확인 kubectl scale deployment nginx-deployment --replicas=15 # 파드 증가 테스트 >> 파드 정상 생성 확인, 워커 노드에서 eth, eni 갯수 확인 kubectl scale deployment nginx-deployment --replicas=30 # 파드 생성 실패! kubectl get pods | grep Pending nginx-deployment-7fb7fd49b4-d4bk9 0/1 Pending 0 3m37s nginx-deployment-7fb7fd49b4-qpqbm 0/1 Pending 0 3m37s 7 # 디플로이먼트 삭제 kubectl delete deploy nginx-deployment ------------------------ 15. 워커 노드 증가(ASG = Auto Scaling Group) 1 # EC2 인스턴스 모니터링 while true; do aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIPAdd:PublicIpAddress,InstanceName:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --output text | sort; echo "------------------------------" ;date; sleep 1; done 2 # 인스턴스그룹 정보 확인 kops get ig (ai-002:my-webs) [root@kops-ec2 ~]# kops get ig NAME ROLE MACHINETYPE MIN MAX ZONES control-plane-ap-northeast-2a ControlPlane t3.medium 1 1 ap-northeast-2a nodes-ap-northeast-2a Node t3.medium 1 1 ap-northeast-2a nodes-ap-northeast-2c Node t3.medium 1 1 ap-northeast-2c 3 # 노드 추가 kops edit ig nodes-ap-northeast-2a --set spec.minSize=2 --set spec.maxSize=2 # node 축소 kops edit ig nodes-ap-northeast-2a --set spec.minSize=1 --set spec.maxSize=1 # 적용 kops update cluster --yes && echo && sleep 3 && kops rolling-update cluster 5 (ai-002:my-webs) [root@kops-ec2 ~]# kops get ig -------------------- 16. kops로 클러스터 삭제 1 # kops로 클러스터 삭제 kops delete cluster --yes # cloudformation 삭제 , 명령 ec2 삭제 aws cloudformation delete-stack --stack-name mykops