1
votes

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?

1
Hi Jacob, can you elaborate on your confusion. - damitj07
@damitj07 - I modified the confusion how I felt in question. Guide me If I went in wrong way. My confusion is that for using kubectl set image for first deployment in my pipeline.Can you look on question please? - Jacob
Or 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. - damitj07
yes , SO think of it as each repo' has its own deployment.yml inside it. So when for first time code is checked-in you can use that yml to check if deployment already excists ? if it does not just create the development with kubectl apply or in case of second commit kubectl set image will work - damitj07
You just need the name or some way to recognize if it is first commit or not. And you can use any method to do it. - damitj07

1 Answers

2
votes

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.