Deploying docker container from amazon Ecr to kubernetes using Jenkins it has a lot to go with
Let’s go with an example
Let’s say
I have my Continuous Integration work-flow
Build my code and install dependencies
Create a container with a unique tag ( commit-id ) > my-center:12
Push to ECR
Curl Rancher API for my-pod > set(image:my-center:12)
Kubernates updates the pod and pulls the container with tag 12 from ECR
Now let’s go with the script
- composer install --no-interaction
- docker build -t cms .
- docker tag myrepo:latest 123456789.dkr.ecr.my-region.amazonaws.com/myrepo:$BITBUCKET_BUILD_NUMBER
- aws ecr get-login --no-include-email --region my-region >> login.sh
- sh login.sh
- docker push 123456799.dkr.ecr.my-region.amazonaws.com/myrepo:$BITBUCKET_BUILD_NUMBER
- sh .docker/workload-update.sh // my curl script calling rancher API
Here I have used the rancher API to update pods and its configuration
Now for the ECR credentials part for Kubernetes, you have to create a secret ( a Kubernetes only entity) which is created by using amazon ecr details.
This secret is used in your pod.yaml as image-pull-secret which will tell k8 to use the secret and pull image from ECR.
For that, I will show the script that helps you how to use it in pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-app
labels:
app: my-app
spec:
containers:
- image: 123456789.dkr.ecr.my-region.amazonaws.com/my-repo
name: -center
ports:
- containerPort: 8080
imagePullSecrets:
- name: my-secret-name ( this will be same as the name of secret we created earlier)
Thus you can build the required your desired thing from the above example.