1 서울리전 cloudformation ec2 2 # 터미널 1 wa 3 # 터미널 2 mkdir 70 cd 70 aws configure AKIA2ESL w5ENTWN ap-northeast-2 aws s3 ls 4 cat << 'EOF' > eks-cluster.yaml apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: my-eks-cluster region: ap-northeast-2 version: "1.34" availabilityZones: - ap-northeast-2a - ap-northeast-2b - ap-northeast-2c vpc: cidr: 10.0.0.0/16 clusterEndpoints: publicAccess: true privateAccess: false nat: gateway: Disable iam: withOIDC: true managedNodeGroups: - name: ng-worker instanceType: t3.small minSize: 1 maxSize: 4 desiredCapacity: 2 volumeSize: 20 volumeType: gp3 volumeEncrypted: true privateNetworking: false amiFamily: AmazonLinux2023 availabilityZones: - ap-northeast-2a - ap-northeast-2b - ap-northeast-2c labels: role: worker env: dev tags: Name: my-eks-worker Environment: dev iam: attachPolicyARNs: - arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy - arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore addons: - name: vpc-cni version: latest - name: coredns version: latest - name: kube-proxy version: latest cloudWatch: clusterLogging: enableTypes: - api - audit - authenticator - controllerManager - scheduler EOF # 클러스터 생성 eksctl create cluster -f eks-cluster.yaml (15분) 5 k get no kubectl get nodes # 노드 목록 보기 kubectl get pods # 파드 목록 보기 kubectl get pods -A # 모든 네임스페이스 파드 kubectl get services # 서비스 목록 보기 kubectl create deployment my-app --image=nginx kubectl scale deployment my-app --replicas=3 kubectl expose deployment my-app --port=80 kubectl describe pod my-pod-name # 파드 상세 정보 kubectl logs my-pod-name # 파드 로그 보기 kubectl exec -it my-pod -- sh # 파드 내부 접속 kubectl delete pod my-pod-name # 파드 삭제 6 cat << 'EOF' > mario.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mario labels: app: mario spec: replicas: 1 selector: matchLabels: app: mario template: metadata: labels: app: mario spec: containers: - name: mario image: pengbai/docker-supermario:latest ports: - containerPort: 8080 resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "200m" memory: "256Mi" --- apiVersion: v1 kind: Service metadata: name: mario-service labels: app: mario spec: type: LoadBalancer selector: app: mario ports: - protocol: TCP port: 80 targetPort: 8080 EOF # 배포 kubectl apply -f mario.yaml 7 # 파드 상태 확인 kubectl get pods -l app=mario # LoadBalancer 주소 확인 (1~3분 소요) kubectl get svc mario-service # EXTERNAL-IP 나올 때까지 대기 watch kubectl get svc mario-service # 접속 http:// (3분후 접속 됨) 8 # 실습 종료시 클러스터 삭제 # 삭제후 재 설치는 20분후 재설치 가능하다. 삭제 중인지 확인법 eksctl delete cluster --region=ap-northeast-2 --name=my-eks-cluster # CloudFormation 스택 삭제 상태 확인 (eksctl은 CFN으로 리소스 관리) aws cloudformation list-stacks \ --region ap-northeast-2 \ --stack-status-filter DELETE_IN_PROGRESS \ --query 'StackSummaries[*].{Stack:StackName, Status:StackStatus}' \ --output table while true; do RESULT=$(aws cloudformation list-stacks \ --region ap-northeast-2 \ --stack-status-filter DELETE_IN_PROGRESS \ --query 'StackSummaries[?contains(StackName, `my-eks-cluster`)].{Stack:StackName, Status:StackStatus}' \ --output table) clear echo "=== $(date '+%Y-%m-%d %H:%M:%S') ===" if [ -z "$(echo $RESULT | grep 'my-eks-cluster')" ]; then echo "✅ 삭제 완료! 클러스터가 없습니다." break else echo "$RESULT" echo "⏳ 삭제 진행 중... 10초 후 재확인" fi sleep 10 done # 콘솔의 cloudformation에서도 확인가능. watch -d eksctl get cluster --region ap-northeast-2