I manage to push my image to google cloud registery but when I try to rolling upgrade my cluster nothing happen.
I check my pods and they are not restarted.
I think I'm missing a command to force the rolling upgrade but I can't found help into the circle ci documentation wich is really low : https://circleci.com/docs/2.0/google-container-engine/
my circle.yml :
version: 2
jobs:
build:
docker:
- image: google/cloud-sdk:latest
steps:
- checkout
- run:
name: Install Docker client
command: |
set -x
VER="17.03.0-ce"
curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv -f /tmp/docker/* /usr/bin
- run:
name: Install Docker Compose
command: |
set -x
curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /tmp/docker-compose
mv -f /tmp/docker-compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
- type: setup-docker-engine
- run:
name: Build Docker image
command: |
docker build -t eu.gcr.io/${GOOGLE_PROJECT_ID}/gcp-test:latest .
- run:
name: Dump Google Cloud Credentials to file
command: |
echo ${GOOGLE_AUTH} > ${HOME}/gcp-key.json
gcloud auth activate-service-account --key-file ${HOME}/gcp-key.json
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
gcloud --quiet container clusters get-credentials ${GOOGLE_CLUSTER_NAME}
- run:
name: Push the image to google registery
command: |
gcloud docker -- push eu.gcr.io/${GOOGLE_PROJECT_ID}/gcp-test:latest
- run:
name: Deploy image to the gc cluster
command: |
kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl set image deployment/solive-deployment node-app=eu.gcr.io/${GOOGLE_PROJECT_ID}/gcp-test:latest
kubectl get deployments
kubectl get pods
A solution to force the re-pull of the image is to change the pod-template hash during each build. This can be achieved by adding an environment variable that is altered during build:
deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: demo
spec:
replicas: 1
template:
metadata:
labels:
app: demo
spec:
containers:
- name: demo
image: registry.example.com/apps/demo:master
imagePullPolicy: Always
env:
- name: FOR_GODS_SAKE_PLEASE_REDEPLOY
value: 'THIS_STRING_IS_REPLACED_DURING_BUILD'
deploy:
sed -ie "s/THIS_STRING_IS_REPLACED_DURING_BUILD/$(date)/g" deployment.yml
kubectl apply -f deployment.yml
Full credits to the original answer - https://github.com/kubernetes/kubernetes/issues/33664#issuecomment-292895327
Pods do not restart when you do kubectl apply -f deployment.yml
, but the image they are running on will be updated (the container will be stopped and started with the new image).
In my experience it is not necessary to update the service or to set image
.
Note that my answer shouldn't be taken for granted as I am far from an expert in Kubernetes.