Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically deploy new image to k8s cluster as it was pushed to docker registry?

I have configured dockerhub to build a new image with tags latest and dev-<version> as new tag <version> is appeared in GitHub. I have no idea how to configure Tekton or any other cloud-native tool to automatically deploy new images as they become available at the registry.

Here's my k8s configuration:

apiVersion: v1
kind: List
items:
  - apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: my-app-ingress
    spec:
      rules:
        - http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: my-app-service
                    port:
                      number: 80
  - apiVersion: v1
    kind: Service
    metadata:
      name: my-app-service
    spec:
      ports:
        - port: 80
          targetPort: 8000
      selector:
        app: my-app
      type: LoadBalancer

  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app-local-deployment
      labels:
        app: my-app
        type: web
    spec:
      replicas: 2
      minReadySeconds: 15
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxUnavailable: 25%
          maxSurge: 1
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          imagePullSecrets:
            - name: regcred
          containers:
            - name: backend
              image: zuber93/my-app:dev-latest
              imagePullPolicy: IfNotPresent
              envFrom:
                - secretRef:
                    name: my-app-local-secret
              ports:
                - containerPort: 8000
              readinessProbe:
                httpGet:
                  path: /flvby
                  port: 8000
                initialDelaySeconds: 10
                periodSeconds: 5
            - name: celery
              image: zuber93/my-app:dev-latest
              imagePullPolicy: IfNotPresent
              workingDir: /code
              command: [ "/code/run/celery.sh" ]
              envFrom:
                - secretRef:
                    name: my-app-local-secret
            - name: redis
              image: redis:latest
              imagePullPolicy: IfNotPresent
like image 254
Vassily Avatar asked Oct 27 '25 09:10

Vassily


1 Answers

Short answer is: Either setup a webhook from dockerhub (https://docs.docker.com/docker-hub/webhooks/) to tekton using triggers.

Or (depends on your security and if your cluster is reachable from www or not)

Poll dockerhub and trigger tekton upon new image detection. (This can be done in many different ways, simple instant service, scheduled cronjob, etc in k8s)

So, you choose push or pull. ;)

I would ask "why not trigger from your git repo directly?"

like image 166
MrSimpleMind Avatar answered Oct 30 '25 05:10

MrSimpleMind