0

I have a git hub workflow which builds an image and pushers to gcr container as below

 steps:
    # Checkout the repository to the GitHub Actions runner
    - name: Checkout
      uses: actions/checkout@v2

    - uses: 'google-github-actions/auth@v1'
      with:
        credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
        export_default_credentials: true  

    # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
    - name: Configure Docker
      run: gcloud auth configure-docker --quiet


    # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
    - name: Build Docker image in prod
      run: docker build . --tag gcr.io/${{ secrets.GCP_PROJECT_ID }}/pythonapp:latest
    # Generates an execution plan for Terraform
    - name: Push Docker image in prod
      run: docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/pythonapp:latest

as u see everytime it builds an image with latest tag.

Now i have the deployment yaml file as below

spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: gcr.io/projectid/pythonapp:latest
          ports:
            - containerPort: 5000
          imagePullPolicy: Always

However the code doesnt get updated in the deployment automatically when a new image with 'latest' tage is pushed.

I have to do

kubectl delete -f app.yaml
kubectl create -f app.yaml

for the changes to take into effect. Is there any other things to be taken care so that it gets updated automatically when a new image is found?

  • 1
    Don't use the `latest` tag. In the context of your CI system you probably have some more unique values like the commit ID available; use that as your image tag, and change the `image:` in the Deployment to match (maybe using a layer like Helm or Kustomize). – David Maze Jun 20 '23 at 11:08
  • 1
    Kubernetes doesn't check if the image have changed. It relied on the Tags. So as David mentioned you need to tag your images with something other than latest and update the deployment – boredabdel Jun 20 '23 at 12:39

0 Answers0