CI/CD Plan
CI : build and push the image to ecr.
CD : deploy the new image to eks cluster.
2-1. Make a helm chart of app.
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.simpleApiService.serviceName }}
spec:
selector:
name: {{ .Values.simpleApiService.serviceName }}
type: NodePort
ports:
- name: http
protocol: TCP
nodePort: {{ .Values.simpleApiService.mainPort }}
port: {{ .Values.simpleApiService.mainPort }}
targetPort: 8000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.simpleApiService.serviceName }}
spec:
replicas: 1
selector:
matchLabels:
name: {{ .Values.simpleApiService.serviceName }}
template:
metadata:
labels:
name: {{ .Values.simpleApiService.serviceName }}
spec:
containers:
- name: {{ .Values.simpleApiService.serviceName }}
image : {{ .Values.simpleApiService.image.repository }}:{{ .Values.simpleApiService.image.tag }}
ports :
- containerPort: 8000
This is sample helm chart for deploy app.
Istio/ingress setting will be needed.
2-2. Associate the chart and skaffold
apiVersion: skaffold/v3
kind: Config
metadata:
name: simple-api
build:
artifacts:
- image: simple-api
context: testapp
# cacheFrom:
docker:
dockerfile: Dockerfile
local:
useBuildkit: true
profiles:
- name: main
deploy:
helm:
releases:
- name: simple-api
chartPath: deploy/helm/mychart
valuesFiles: [deploy/helm/mychart/values.yaml]
wait: true
Add the deploy part on the previous skaffold file.
2-3. modify github action
Install kubectl to runner.
Before deploy pod, check the pod capacity. ec2 instance has default maximum pods .
steps:
- uses: actions/checkout@v2
- uses: FranzDiebold/github-env-vars-action@v2
- name: Configure AWS credentails
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: get KUBE CONFIG
id: kubeconfig
run: aws eks update-kubeconfig --name ${{ vars.EKS_CLUSTER_NAME }} --role ${{ vars.EKS_CLUSTER_ACCESS_ARN }}
- name: Create namespace
continue-on-error: true
run: kubectl create ns $CI_ACTION_REF_NAME_SLUG || echo "Already created or failed!"
- name: Skaffold appy
id: skaffold-apply
run: skaffold run -n $CI_ACTION_REF_NAME_SLUG -f deploy/skaffold/simple-api.yaml --default-repo {ecr repo} -p ${{ env.BUILD_ENV }}
Add the kubeconfig step to get a target cluster and change the skaffold command build -> run(build + deploy).
Now, if the action is triggerd, app is build and deployed to target cluster.