What is the industry standard solution for creating a deployment using CI (Jenkins) using kubectl set image command in kubernetes

11/7/2019

Currently I am working with implementation demo of CI/CD pipeline using Jenkins and kubernetes. I am created one Jenkins pipeline job and added every step in my Jenkinsfile. For kubernetes , I created deployment and service YAML files for Kubernetes resources.

Image Version Management In deployment

For each commit in my SVN repository , I am creating docker images by adding the tag as build number through Jenkins environment variable.

image:1
image:2
.
.
image:n

Confusion

If I am using kubectl set image command for updating my deployment in my Jenkinsfile deployment stage , then It will work for first commit ?

I felt this confusion , because command says that it is for updating the deployment if there is change in image defined in YAML file. So If I am changing image for each commit according to build number( image-name:buildnumber) , then if there is no deployment exits , it will work for first time?

-- Jacob
continuous-deployment
jenkins
kubernetes

1 Answer

11/7/2019

So I can think of multiple ways, one a bit hacky and other that I like. You can decide based on waht is best suited for you.

Solution 1 - You can add a simple conditional check-in your Jenkins, for the first time if deployment does not exists create it and set it to the first image. And from the second commit onwards update.

OR

Solution 2 - Think of it as each repository or service should have its own deployment.yml within it. So when for first time code is checked-in you can use that yml to check if deployment already exists ? if it does not just create the development with kubectl apply myapp.yml and for the second commit kubectl set image will work.

-- damitj07
Source: StackOverflow