DEV Community

Jeg
Jeg

Posted on

Getting the latest tagged image to the AKS cluster while deploying the application

I came across a scenario where the application is developed and built as a docker image with the tag (xxx.azurecr.io/sampleimage:latest). Then the built docker image is pushed to the Azure container registry.

The pushed docker image is then deployed in the AKS cluster using kubectl apply -f filename.yaml

Now, the code base is updated and the docker image is also updated with the same tag (xxx.azurecr.io/sampleimage:latest) and pushed to the container registry. The container registry is now having an image with the latest code base.

For the latest image (the one which is updated 2nd time - as mentioned above) to get deployed in the AKS cluster, we need to use imagePullPolicy as Always in the yaml files. If it is not set, the AKS cluster would only take the already available image (the one which is pushed first) from the cluster.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-tomcat-helloworld
  labels:
    app: test-tomcat-helloworld
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-tomcat-helloworld
  template:
    metadata:
      labels:
        app: test-tomcat-helloworld
    spec:
      containers:
      - name: test-tomcat-helloworld
        image: cicdcontainervol.azurecr.io/test-tomcat-helloworld:v1
        imagePullPolicy: Always
        resources:
          limits:
            memory: "2Gi"
            cpu: "1200m"
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: secret
---
apiVersion: v1
kind: Service
metadata:
    name: test-tomcat-helloworld
    annotations:
      service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
    type: LoadBalancer
    loadBalancerIP: xx.xx.xxx.xx
    ports:
    - port: 8080
      targetPort: 8080
    selector:
        app: test-tomcat-helloworld
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)