EKS에 배포
이제 Weve Flux를 사용하여 Hello world 애플리케이션을 Amazon EKS 클러스터에 배포할 준비가 되었습니다. 이를 위해 GitHub config repository(k8s-config)를 복제한 다음 배포할 Kubernetes 매니페스트를 commit합니다.
cd ..
git clone git@github.com:${YOURUSER}/k8s-config.git
cd k8s-config
mkdir charts namespaces releases workloads
네임스페이스를 생성합니다.
cat << EOF > namespaces/eks-example.yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
name: eks-example
name: eks-example
EOF
Deployment 파일을 생성합니다.
ECR 저장소 및 이미지 태그를 가리키도록 아래 값을 업데이트하십시오. 이미지 URI는 Amazon ECR 콘솔에서 찾을 수 있습니다.
cat << EOF > workloads/eks-example-dep.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: eks-example
namespace: eks-example
labels:
app: eks-example
annotations:
# Container Image Automated Updates
flux.weave.works/automated: "true"
# do not apply this manifest on the cluster
#flux.weave.works/ignore: "true"
spec:
replicas: 1
selector:
matchLabels:
app: eks-example
template:
metadata:
labels:
app: eks-example
spec:
containers:
- name: eks-example
image: <YOURACCOUNT>.dkr.ecr.ap-northeast-2.amazonaws.com/eks-example:YOURTAG
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
EOF
위에는 Flux에 대한 2개의 kubernetes annotation이 있습니다.
flux.weave.works/automated : container image를 자동으로 업데이트해야 하는지 결정.
flux.weave.works/ignore : Flux에서 배포를 일시적으로 무시하도록 함.
마지막으로 서비스 매니페스트를 생성하여 로드 밸런서를 생성할 수 있도록 합니다.
cat << EOF > workloads/eks-example-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: eks-example
namespace: eks-example
labels:
app: eks-example
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: eks-example
EOF
생성된 디렉토리 입니다.

k8s-config git에 변경된 내용을 commit 을 수행합니다.
git add .
git commit -am "eks-example-deployment"
git push
flux pod의 로그를 확인합니다. 5분마다 k8s 구성 저장소에서 구성을 꺼냅니다. 아래의 Pod 이름을 배포 환경에 있는 이름으로 바꾸십시오.
kubectl get pods -n flux
kubectl logs <flux-5bd7fb6bb6-4sc78> -n flux

이제 로드 밸런서 URL(LoadBalancer Ingress)을 가져오고 브라우저를 통해 연결합니다. (DNS의 경우 몇 분 정도 걸릴 수 있습니다).
kubectl describe service eks-example -n eks-example

로드 밸런서 DNS로 접속하면 Hello World 애플리케이션을 확인 할 수 있습니다.

eks-example 소스 코드를 변경하고 새 변경 사항을 푸시합니다.
cd ../eks-example
vi src/index.html
# Change the <title> AND <h> to Hello World Version 2

git commit -am "v2 Updating home page"
git push
이제 CodePipline 콘솔에서 새 이미지 빌드가 완료되는 것을 볼 수 있습니다. 이 작업은 몇 분 정도 걸립니다. 완료되면 Amazon ECR 저장소에 새 이미지가 표시됩니다. Flux pod의 kubectl logs 를 모니터링하면 5분 이내에 구성이 업데이트되는 것을 확인할 수 있습니다.

브라우저에서 페이지를 새로 고쳐 웹 페이지가 업데이트 되었는지 확인합니다.
다시 복구를 하기 위해서 eks의 코드를 수정하고 새로운 이미지 빌드 및 배포를 트리거 할 수 있습니다. 하지만 git을 사용하여 k8s-config의 구성 변경을 되돌릴 수도 있습니다.
cd ../k8s-config
git pull
git log --oneline
git revert HEAD
# Save the commit message
git log --oneline
git push
이제 flux pod드에 대한 로그를 볼 수 있으며, 그러면 구성 변경이 pull되고 이전 이미지가 roll-out 됩니다. 브라우저에서 URL이 되돌아가는지 확인합니다.
Last updated
Was this helpful?