Apply a specific deployment file when running an image on Minikube

8/19/2020

On Minikube using KubeCtl, I run an image created by Docker using the following command:

kubectl run my-service --image=my-service-image:latest --port=8080 --image-pull-policy Never

But on Minukube, a different configuration is to be applied to the application. I prepared some environment variables in a deployment file and want to apply them to the images on Minikube. Is there a way to tell KubeCtl to run those images using a given deployment file or even a different way to provide the images with those values?

I tried the apply verb of KubeCtl for example, but it tries to create the pod instead of applying the configuration on it.

-- AHH
docker
kubernetes
minikube

1 Answer

8/19/2020

In minukube/kubernetes you need to apply the environment variables in the yaml file of your pod/deployment.

Here is a example of how you can configure the environment variables in a deployment spec:

apiVersion: apps/v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: "Hello from the environment"
    - name: DEMO_FAREWELL
      value: "Such a sweet sorrow"

Here you can find more information abour environment variables.

In this case, if you want to change any value, you need to delete the pod and apply it again. But if you use deployment all modification can be done using kubectl apply command.

-- Mr.KoopaKiller
Source: StackOverflow