Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parameterize image version when passing yaml for container creation

Tags:

Is there any way to pass image version from a varibale/config when passing a manifest .yaml to 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 case is to launch specific image version which is set at kubernetes level, and that the variable is resolved by kubernetes itself at server side.

Thanks and Regards, Ravi

like image 222
user1543211 Avatar asked Mar 06 '17 05:03

user1543211


1 Answers

k8s manifest files are static yaml/json.

If you would like to template the manifests (and manage multiple resources in a bundle-like fashion), I strongly recommend you to have a look at Helm

I've recently created a Workshop which focuses precisely on the "Templating" features of Helm.

Helm does a lot more than just templating, it is built as a full fledged package manager for Kubernetes applications (think Apt/Yum/Homebrew).

If you want to handle everything client side, have a look at https://github.com/errordeveloper/kubegen

Although, at some point, you will need the other features of Helm and a migration will be needed when that time comes - I recommend biting the bullet and going for Helm straight up.

like image 159
Vincent De Smet Avatar answered Oct 14 '22 19:10

Vincent De Smet