How to continuously deploy from jenkins to Kubernetes

5/28/2019

i have a Maven project on my local machine and a docker image in my repo and im using gitlab and jenkins to automate builds, and now with current setup I want to continously deploy to Kubernetes. I have no idea on how this is done. Any input will be appreciated.

my yaml file looks like this

apiVersion: v1
kind: Pod
metadata:
  name: client-pod
  labels:
    component: web
spec:
  containers:
    - name: client
      image: <image>
      ports:
        - containerPort: 3000
-- muzi jack
gitlab
jenkins
kubernetes

3 Answers

5/28/2019

The easiest way will be to set the name of the new image. See here:

kubectl --record deployment.apps/nginx-deployment set image deployment.v1.apps/nginx-deployment nginx=nginx:1.9.1

You will need to have access from your gitlab/Jenkins to your cluster.

Another option will be to use some kind of kubernetes deployment tool such as helm, or any other solution. This case will help you in more complicated scenarios where you also want to update your configuration files (k8s yamls).

-- Amityo
Source: StackOverflow

5/29/2019

Once the image is built and pushed to the container repository you just have to set the new image

>>> docker build -t repo-name/whatever-app:<version>
>>> docker push repo-name/whatever-app:<version>
>>> kubectl set image deployment/my-deployment mycontainer=repo-name/whatever-app:<version>
-- Kurtis Streutker
Source: StackOverflow

5/31/2019

You can use this exemplary jenkins pipeline, to build and deploy your dockerized maven-app to Kubernetes with helm. It consists of following steps:

  1. Git clone and setup
  2. Build and local tests
  3. Publish Docker and Helm
  4. Deploy to dev and test
  5. Deploy to staging and test
  6. Optionally deploy to production and test

It think it's a nice starting point to realize CI/CD with Jenkins & Kubernets.

-- Nepomucen
Source: StackOverflow