How to parameterize image version when passing yaml to create container

Is there a way to transfer the version of the image from varibale / config when passing the .yaml manifest to the kubectl command

Example:

apiVersion: v1 kind: ReplicationController metadata: name: nginx spec: replicas: 1 selector: app: nginx template: metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx:${IMAGE_VERSION} imagePullPolicy: Always resources: limits: cpu: "1.2" memory: 100Mi ports: - containerPort: 80 

Use the case to run a specific version of an image that is set at the level of the kubernets, and that this variable is allowed by the kubernete itself on the server side.

Thanks and Regards, Ravi

+6
source share
2 answers

The k8s manifest files are static yaml / json.

If you want to create manifest templates (and manage multiple resources as packages), I highly recommend that you take a look at Helm

I recently created a Workshop that focuses specifically on the features of Helm's Templates .

Helm does much more than just templates, it is built as a complete package manager for Kubernetes applications (I think Apt / Yum / Homebrew).

If you want to handle all the client side, check out https://github.com/errordeveloper/kubegen

Although at some point you will need other Helm functions, and when it comes time, you will need to migrate - I recommend biting the bullet and going straight up to Helm.

+4
source

Looking at this recently, we decided to just go with sed . Wrap kubectl apply in a small bash script and replace the placeholders before running.

We looked at more sophisticated tools, but we found Helm. However, Helm is a sophisticated technology that does more than just templates. This changes your workflow a lot since you no longer deploy with kubectl and must have a Helm package repository to push your packages. Our assessment was that Helm is not useful for deploying our application and using it, since only templating is redundant.

+1
source

Source: https://habr.com/ru/post/1015509/


All Articles