1 # Kind용 EC2 1대 설치 Cloudformation 사용 kind-ec2 # 터미널 1 watch -d kubectl get svc,hpa,deploy,rs,pods 2 # 터미널 2 k ns default 3 # docker가 설치되어 있어야 kind 설치가능 # 1. Kind 바이너리 다운로드 및 설치 (Linux 기준) curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind # 2. 클러스터 생성 kind create cluster --name my-kind-cluster # 3. 클러스터 정보 확인 kubectl cluster-info --context kind-my-kind-cluster 4 # config.yaml 파일 작성 cat < kind-config.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker EOF # 설정 파일을 이용한 클러스터 생성 kind create cluster --config kind-config.yaml 5 cat < nginx-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 selector: matchLabels: app: my-nginx template: metadata: labels: app: my-nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 EOF kubectl apply -f nginx-deployment.yaml 6 # Pod 생성 여부 확인 kubectl get pods # Deployment 상태 확인 kubectl get deploy 7 kubectl expose deployment nginx-deployment --type=NodePort --port=80 --name=nginx-service kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80 --name=nginx-service-lb http://localhost:8080 을 입력 8 cat < nginx-config.yaml apiVersion: v1 kind: ConfigMap metadata: name: nginx-index-html data: index.html: | My Kubernetes Nginx

Hello, Gemini! 🚀

쿠버네티스 실습 중입니다. YAML 수정이 완료되었습니다!

EOF kubectl apply -f nginx-config.yaml 9 # nginx-deployment.yaml 수정본 cat < nginx-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 5 # 포드 개수를 5개로 설정 selector: matchLabels: app: my-nginx template: metadata: labels: app: my-nginx spec: containers: - name: nginx image: nginx:latest volumeMounts: - name: html-volume mountPath: /usr/share/nginx/html volumes: - name: html-volume configMap: name: nginx-index-html EOF # 수정한 설정 적용 kubectl apply -f nginx-deployment.yaml 10 # 새로운 설정을 가진 포드가 뜨는지 확인 kubectl get pods -w # 포트 포워딩 다시 실행 (기존 창이 꺼졌다면) kubectl port-forward service/nginx-service 8080:80 11 # nginx-deployment의 복제본(replicas)을 2개로 변경 kubectl scale deployment nginx-deployment --replicas=2 12 # 파일 내용 중 replicas 부분을 5로 수정한 뒤 적용 vi nginx-deployment.yaml kubectl apply -f nginx-deployment.yaml 13 # 포드 목록 확인 (5개의 포드가 떠 있어야 함) kubectl get pods # 또는 watch 명령어로 상태 변화 관찰 kubectl get pods -w