Kubernetes: The code change does not appear, is there a way to sync?

1/4/2019

In Dockerfile I have mentioned volume like:

COPY src/ /var/www/html/ but somehow my code changes don't appear like it used to only with Docker. Unless I remove Pods, it does not appear. How to sync it?

I am using minikube.

webserver.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webserver
  labels:
    app: apache
spec:
  replicas: 3
  selector:
    matchLabels:
      app: apache
  template:
    metadata:
      labels:
        app: apache
    spec:
      containers:
      - name: php-apache
        image: learningk8s_website
        imagePullPolicy: Never
        ports:
        - containerPort: 80
-- Volatil3
devops
docker
kubernetes
minikube

1 Answer

1/4/2019

When your container spec says:

image: learningk8s_website
imagePullPolicy: Never

The second time you kubectl apply it, Kubernetes determines that it's exactly the same as the Deployment spec you already have and does nothing. Even if it did generate new Pods, the server is highly likely to notice that it already has an image learningk8s_website:latest and won't pull a new one; indeed, you're explicitly telling Kubernetes not to.

The usual practice here is to include some unique identifier in the image name, such as a date stamp or commit hash.

IMAGE=$REGISTRY/name/learningk8s_website:$(git rev-parse --short HEAD)
docker build -t "$IMAGE" .
docker push "$IMAGE"

You then need to make the corresponding change in the Deployment spec and kubectl apply it. This will cause Kubernetes to notice that there is some change in the pod spec, create new pods with the new image, and destroy the old pods (in that order). You may find a templating engine like Helm to be useful to make it easier to inject this value into the YAML.

-- David Maze
Source: StackOverflow