Auto download images for kubernetes

12/30/2019

I have created this very basic application (myapp.yml):

apiVersion: v1
kind: Service
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  type: LoadBalancer
  ports:
  - port: 5035
    targetPort: 5035
    protocol: TCP
    name: http
  selector:
    app: myapp
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: monapp
        image: xxxxxxx.container-registry.ovh.net/private/myimage
        ports:
        - containerPort: 5035
      imagePullSecrets:
      - name: regcred

When i want to update my application, i push a new image on the repository.

I order to ask kubernetes to download this new image on pods, i run:

kubectl rollout restart deployment/myapp-deployment

Is there a way for kubernetes to automaticly detect a new version of the image is present on the repository and auto update pods without having to launch kubectl rollout ?

Thanks

-- Bob5421
kubernetes

1 Answer

12/30/2019

Kubernetes natively does not have this functionality.You can use Skaffold, which automatically builds the image, pushes it the image registry and updates the corresponding pods/controllers. It can even watch for code changes and rebuild the image as soon as changes are saved with skaffold dev command. This only requires adding a simple skaffold.yaml that specifies the image on the registry and path to the Kubernetes manifests. This workflow is described in details in the Getting Started guide.

Edit: You can configure it with gitlab as below:

services:
  - docker:dind

stages:
  - build

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: tcp://docker:2375
build:
  image:
    name: gcr.io/k8s-skaffold/skaffold:latest
  stage: build
  before_script:
    - docker info
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - skaffold run
  only:
    - master
-- Arghya Sadhu
Source: StackOverflow