어제처럼 인스턴스 생성
보안그룹 규칙
#!/bin/bash
cd /tmp
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
amazon-linux-extras install docker -y
systemctl enable --now docker
curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
usermod -a -G docker ec2-user
docker run -d -p 80:80 --name=test-site sechim052339/web-site:v2.0
사용자 데이터
푸시명령 보기 클릭
// aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: ap-northeast-2
Default output format [None]: json
// push 명령보기 클릭 후 로그인 후 이미지 푸쉬 가능
// 리포지토리 uri 태그 붙이기
[ec2-user@ip-10-19-33-76 ~]$ docker tag sechim052339/web-site:v2.0 public.ecr.aws/b7r5v6j2/test-site:eagle
// 리포지토리에 푸쉬
[ec2-user@ip-10-19-33-76 ~]$ docker push public.ecr.aws/b7r5v6j2/test-site:eagle
ecr 에서 확인하면 이미지가 푸쉬된 것을 알 수 있음
로깅 모두 체크후 생성
https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/install-kubectl.html //kubectl 설치
// kubectl 1.22 버전 설치 명령어
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/bin/linux/amd64/kubectl
chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin
$ source <(kubectl completion bash)
$ echo "source <(kubectl completion bash)" >> ~/.bashrc
// 자동완성
// eks 클러스터 활성되면 명령어 실행
$ aws eks --region ap-northeast-2 update-kubeconfig --name EKS-CLUSTER
// 나오면 성공
[ec2-user@ip-10-19-33-76 ~]$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 172.20.0.1 <none> 443/TCP 6m9s
[ec2-user@ip-10-19-33-76 ~]$ kubectl run nginx-pod1 --image=nginx
[ec2-user@ip-10-19-33-76 ~]$ kubectl expose pod nginx-pod1 --name loadbalancer --type LoadBalancer --port 80
// clb 로드밸런서 생성됨
https 적용, 443 보안그룹 열기
스팟인스턴스 삭제하고 온디맨드 인스턴스로 노드그룹 다시 만듬
[ec2-user@ip-10-19-33-76 test]$ vi replica-loadbalancer.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-replicaset
spec:
replicas: 3
selector:
matchLabels:
app: nginx-replicaset
template:
metadata:
name: nginx-replicaset
labels:
app: nginx-replicaset
spec:
containers:
- name: nginx-replicaset-container
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: loadbalancer-service-replicaset
spec:
type: LoadBalancer
externalIPs:
- 192.168.1.179
- 192.168.1.205
- 192.168.1.209
selector:
app: nginx-replicaset
ports:
- protocol: TCP
port: 80
targetPort: 80
[ec2-user@ip-10-19-33-76 test]$ kubectl apply -f replica-loadbalancer.yaml
// pod 모두 수정
[ec2-user@ip-10-19-33-76 test]$ kubectl exec nginx-replicaset-5hqqd -- sh -c "echo 'web01' > /usr/share/nginx/html/index.html"
[ec2-user@ip-10-19-33-76 test]$ kubectl exec nginx-replicaset-bcxpl -- sh -c "echo 'web02' > /usr/share/nginx/html/index.html"
[ec2-user@ip-10-19-33-76 test]$ kubectl exec nginx-replicaset-cjt74 -- sh -c "echo 'web03' > /usr/share/nginx/html/index.html"
[ec2-user@ip-10-19-33-76 test]$ kubectl exec nginx-replicaset-kw4lw -- sh -c "echo 'web04' > /usr/share/nginx/html/index.html"
롤링 업데이트 확인
[ec2-user@ip-10-19-33-76 test]$ vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 4
selector:
matchLabels:
app: nginx-deployment
template:
metadata:
name: nginx-deployment
labels:
app: nginx-deployment
spec:
containers:
- name: nginx-deployment-container
image: nginx
ports:
- containerPort: 80
apply
# vi clusterip-deployment.yaml # 클러스터아이피 야믈
apiVersion: v1
kind: Service
metadata:
name: clusterip-service-deployment
spec:
type: ClusterIP
externalIPs:
- 10.19.5.184 // worker1의 프라이빗 ip 붙여주면
selector:
app: nginx-deployment
ports:
- protocol: TCP
port: 80
targetPort: 80
클러스터 ip 인데 프라이빗 ip 붙이면 잘 될지 확인해봄.
보안그룹 열어주고 확인하기
디폴로이먼트를 사용하는 이유 롤링 업데이트에 용이
봄철 홈페이지 개편같은 것들을 할 수 있음
kubectl set image deployment.apps/nginx-deployment nginx-deployment-container=public.ecr.aws/b7r5v6j2/test-site:eagle