taibc
taibc

Reputation: 923

kubernetes deploy plugin in Jenkins doesn't update pod

I use kubernetes-cd plugin in Jenkins (https://plugins.jenkins.io/kubernetes-cd/) to deploy my application successfully.

enter image description here

But, I got a problem, when I re-run the job again, the jenkins doesn't update my pod (doesn't delete and create new pod again), so my changes of code aren't affected. And after I delete the pod manual using kubectl commands in kubernetes cluster and re-run the job, it make changes

Below is my yaml file. Do you know how to fix this ?

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: tds-upload
  name: tds-upload
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tds-upload
  template:
    metadata:
      labels:
        app: tds-upload
    spec:
      containers:
      - image: dev-master:5000/tds-upload:1.0.0
        imagePullPolicy: Always
        name: tds-upload

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: tds-upload
  name: tds-upload
spec:
  ports:
  - nodePort: 31313
    port: 8889
    protocol: TCP
    targetPort: 8889
  selector:
    app: tds-upload
  type: NodePort

Upvotes: 0

Views: 1508

Answers (1)

Arghya Sadhu
Arghya Sadhu

Reputation: 44569

There are different ways to make Kubernetes deploy new changes.

  1. kubectl rollout restart deployment myapp

This is the current way to trigger a rolling update and leave the old replica sets in place for other operations provided by kubectl rollout like rollbacks

  1. kubectl patch deployment my-deployment -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"build\":\"$CI_COMMIT_SHORT_SHA\"}}}}}}"

Where you can use any name and any value for the label as long as it changes with each build.

You can use the kubectl cli plugin of Jenkins to execute above commands.

Upvotes: 1

Related Questions