Issue
i am quite new to Jenkins and Kubernetes and i am not sure if this way to deploy to kubernetes is right or maybe there is better way to do this. All images are build using Jenkins and then deployed to kubernetes. Yaml files are placed in kubernetes server (centos 7). Using jenkins pipeline ssh to kubernetes server and run kubectl delete
sh label: '', script: 'sshpass -p PASSWORD ssh -o StrictHostKeyChecking=no USER@SERVER kubectl delete svc SERVICE || true '
Next similar code is run to delete deployment and then to create deployment kubectl create filename.yaml is run. This was ok at the beginning but now i noticed that there is downtime since services and deployments are being deleted and recreated.. Should I start using some plugins to make it easier and better? Should yaml files be placed somewhere else so if i need to do some changes i would not need to connect to Kubernetes Centos and make changes there? maybe someone could give me some links to read or have some good practices about this? Thanks in advance!
Solution
There is no better or worst way, but there is a way that works for your.
You can keep all your kubernetes file (yamls files) on a git repository, and them when you run the pipeline the Jenkins will retrive these repository to run.
I'm not sure why you are deleting the resources before apply, but if you are using a kind: deployment
you can use the command kubectl apply
with rollingUpdate
strategy to avoid downtimes.
Here you can find a lot of useful information about deployment strategy with Jenkins.
Other useful links:
Answered By - Mr.KoopaKiller
Answer Checked By - Willingham (JavaFixing Volunteer)