EKS 클러스터 생성 실습
마지막 업데이트
마지막 업데이트
aws --version
eksctl version
kubectl version --clientaws sts get-caller-identity{
"UserId": "AIDACKCEVSQ6C2EXAMPLE",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/your-user"
}export AWS_DEFAULT_REGION=ap-northeast-2
echo "Region: $AWS_DEFAULT_REGION"cat > /tmp/eks-cluster.yaml << 'EOF'
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: lab-cluster
region: ap-northeast-2
version: "1.31"
managedNodeGroups:
- name: workers
instanceType: t3.medium
desiredCapacity: 2
minSize: 1
maxSize: 3
volumeSize: 20
EOFeksctl create cluster -f /tmp/eks-cluster.yamlkubectl config current-context
kubectl cluster-infokubectl get nodes
# 2개의 Ready 노드가 표시되어야 합니다kubectl get nodes -o wide
kubectl describe node $(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')kubectl get pods -n kube-system
kubectl get svc -n kube-systemkubectl top nodes 2>/dev/null || echo "Metrics Server가 설치되지 않았습니다"kubectl create deployment nginx --image=nginx:1.25 --replicas=2
kubectl expose deployment nginx --port=80 --type=LoadBalancer
kubectl wait --for=condition=available deployment/nginx --timeout=120s# LoadBalancer External IP 확인 (ELB 생성에 몇 분 소요)
kubectl get svc nginx -w
# EXTERNAL-IP가 할당되면 Ctrl+C
# 접근 테스트
ELB_URL=$(kubectl get svc nginx -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "ELB URL: $ELB_URL"
curl -s "$ELB_URL" | head -5kubectl scale deployment nginx --replicas=4
kubectl get pods -l app=nginx -o widekubectl get deployment nginx -o jsonpath='{.status.readyReplicas}'
# 출력: 4# 1. 애플리케이션 정리 (LoadBalancer가 ELB를 삭제하도록)
kubectl delete svc nginx
kubectl delete deployment nginx
# 2. ELB 삭제 대기 (약 1분)
sleep 60
# 3. 클러스터 삭제
eksctl delete cluster -f /tmp/eks-cluster.yaml --wait
# 4. 설정 파일 정리
rm -f /tmp/eks-cluster.yamlaws eks update-kubeconfig --name lab-cluster --region ap-northeast-2