Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernates pass env variable to "kubectl create"

I need to pass dynamic env variable to kubectl create. Something like this

kubectl create -f app.yaml --Target=prod

Based on Target code deploys on different servers.

like image 253
Rohith Avatar asked May 11 '18 17:05

Rohith


People also ask

How do I pass an env file in Kubernetes?

There are two ways to define environment variables with Kubernetes: by setting them directly in a configuration file, from an external configuration file, using variables, or a secrets file. This tutorial shows both options, and uses the Humanitec getting started application used in previous tutorials.

How do you pass environment variables in pod?

When you create a Pod, you can set dependent environment variables for the containers that run in the Pod. To set dependent environment variables, you can use $(VAR_NAME) in the value of env in the configuration file.


1 Answers

If you want to avoid installing 3rd party plugin then you can replace the text using sed "s/orginal/change/". It worked. I used this in Jenkins shell.

cat app.yaml | sed "s/l3-apps/l2-apps/" | kubectl create -f -

like image 197
Rohith Avatar answered Oct 08 '22 03:10

Rohith