6. kops로 k8s 클러스터 생성(필수) 1 aws configure AWS Access Key ID [None]: AKIAU6GD27X AWS Secret Access Key [None]: dBIAaEjtc9dQbzLfQYio5+JQ Default region name [None]: ap-northeast-2 Default output format [None]: <엔터> aws s3 ls 2 REGION=ap-northeast-2 aws s3 mb s3://agame-bk111 --region $REGION 3 # 버킷 이름과 도메인명을 맟춰 주세요. export AWS_PAGER="" export REGION=ap-northeast-2 export KOPS_CLUSTER_NAME=ai-002.click export KOPS_STATE_STORE=s3://agame-bk11 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-bk11' >>~/.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.34.0" -y 결과 Cluster is starting. It should be ready in a few minutes. Suggestions: * validate cluster: kops validate cluster --wait 10m * list nodes: kubectl get nodes --show-labels * ssh to a control-plane node: ssh -i ~/.ssh/id_rsa ubuntu@ * the ubuntu user is specific to Ubuntu. If not using Ubuntu please use the appropriate user based on your OS. * read about installing addons at: https://kops.sigs.k8s.io/addons. (ai-002:N/A) [root@kops-ec2 ~]# 이후 노드 생성과 노드 확인 가능. 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 ------------------ # 확인 kops get cluster kops get instances kubectl get nodes -v6 --------------- 9. 디플로이먼트 배포 wget https://github.com/topasvga1/mario1/blob/main/mario.yaml kubectl apply -f mario.yaml (5분) # LoadBalancer 확인하기 watch -d kubectl get deploy,rs,pods,svc 7 확장 kubectl scale deployment mario --replicas=3 8 삭제 테스트 kubectl delete pod파드명 삭제 되었나요 ? 9 삭제 # 디플로이 먼트로 삭제 k delete deployment.apps/mario # 서비스 삭제 k delete svc mario 여기까지 잘 되었나요? --------------------------------- 10. 멱등성 테스트 - 선택 1 # 터미널 1 (모니터링) watch -d kubectl get deploy,rs,pod 2 # 터미널 2 kubectl create namespace my-webs k ns my-webs # Deployment 배포(Pod 3개) kubectl create deployment my-webs --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --replicas=3 kubectl get pod -w # 파드 증가 및 감소 kubectl scale deployment my-webs --replicas=5 kubectl scale deployment my-webs --replicas=6 && kubectl get pod -w kubectl get pod # 강제로 파드 삭제 kubectl delete pod --all && kubectl get pod -w kubectl get pod pod가 지워지고 다시 생겨난다. 3 # 실습 완료 후 Deployment 삭제 kubectl scale deployment my-webs --replicas=30 kubectl delete deploy my-webs ------------------------- 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 ------------------------ 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 2 콘솔로 수동 삭제시는 Autoscaling 그룹부터 지워야 한다. 그렇지 않으면 삭제한 EC2가 다시 생성된다. 감사합니다.