Docker VotingApp build/release Jenkins on Kubernetes not idempotent

8/15/2017

I'm trying out deployments on Kubernetes via Jenkins with the Docker Voting App. I use the Azure Container registry as a repository for the docker images. On first try all is deployed ok: enter image description here

When I re-run the pipeline without changing something I get the following error: enter image description here

Redis service definition:

---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: redis
    version: alpine
  name: redis
  selfLink: /api/v1/namespaces//services/redis
spec:
  clusterIP: 
  ports:
  - name: 
    port: 6379
    protocol: TCP
    targetPort: 6379
  selector:
    app: redis
    version: alpine
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
---

The docker images are build with "latest" tag.

stage 'Checkout'
node {
    git 'https://github.com/*****/example-voting-app.git' // Checks out example votiung app repository
   stage 'Docker Builds'
   docker.withRegistry('https://*****.azurecr.io', 'private-login') {
        parallel(
            "Build Worker App":{def myEnv = docker.build('*****.azurecr.io/example-voting-app-worker:latest', 'worker').push('latest')},
            "Build Result App":{def myEnv = docker.build('*****.azurecr.io/example-voting-app-result:latest', 'result').push('latest')},
            "Build Vote App":{def myEnv = docker.build('*****.azurecr.io/example-voting-app-vote:latest', 'vote').push('latest')}
            )
    }
    stage 'Kubernetes Deployment'
    sh 'kubectl apply -f kubernetes/basic-full-deployment.yml'
    sh 'kubectl delete pods -l app=vote'
    sh 'kubectl delete pods -l app=result'
    stage 'Smoke Test'
    sh 'kubectl get deployments'
}
-- RedAnsible
azure
docker
jenkins
kubernetes

1 Answer

8/15/2017

Your definition contains fields that are auto-generated/managed by the apiserver. Some of them are created at the time of object creation and can't be updated afterwards. Remove the following fields from your file to make it happy:

metadata:
  creationTimestamp: null
  selfLink: /api/v1/namespaces//services/redis
status:
  loadBalancer: {}
-- Janos Lenart
Source: StackOverflow