Managing Create & Update of Kubernetes Deployment in CI/CD pipeline Implementation

10/31/2019

Currently I am trying to implement demo for CI/CD pipeline using SVN , Kubernetes and Jenkins. For kubernetes deployment, I created deployment and services.And for making deployment I am using kubectl apply -f command for both deployment inside my Jenkins deployment step.

Like the following ,

stage ('Test Deployment')
        {
             steps
                {
                    sh 'kubectl apply -f deployment/testdeployment.yaml'
                    sh 'kubectl apply -f deployment/testservice.yaml'
                }
        }

and service.

For each commit to my SVN repo will trigger this jenkins pipeline job and will execute the commands. After modifying any changes in code the same kubectl apply command is executing.

Here my confusion is that ,

  1. Can I use kubectl apply command is for updating the existing deployment ?
  2. Or Do I need to use the command kubectl rollout restart ?

For continuous deployment process in CI/CD pipeline implementation , Which command I need to use in my Jenkinsfile for updating the deployment when commit is made to SVN repository?

-- Jacob
continuous-deployment
kubernetes

1 Answer

10/31/2019

You can use the Kubectl apply command as long as the name of resources in the deployment and service file has not changed. From the Kubernetes book,

Apply is a command that will update a Kubernetes cluster to match state defined locally in files.

kubectl apply

Fully declarative - don't need to specify create or update - just manage files

The parameters relating to rolling deployment such as how many pods should be available and how many can be taken out of active deployment you can check this documentation.

-- Vishal Biyani
Source: StackOverflow