rendering env-var inside kubernetes kubeconfig yaml file

9/10/2019

I need to use an environment variable inside my kubeconfig file to point the NODE_IP of the Kubernetes API server.

My config is:

apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://$NODE_IP:6443
  name: docker-for-desktop-cluster
contexts:
- context:
    cluster: docker-for-desktop-cluster
    user: docker-for-desktop
  name: docker-for-desktop
current-context: docker-for-desktop
kind: Config
preferences: {}
users:
- name: docker-for-desktop
  user:
......

But it seems like the kubeconfig file is not getting rendered variables when I run the command:

kubectl --kubeconfig mykubeConfigFile get pods.

It complains as below:

Unable to connect to the server: dial tcp: lookup $NODE_IP: no such host

Did anyone try to do something like this or is it possible to make it work?

Thanks in advance

-- oguz
kubeconfig
kubernetes
yaml

1 Answer

9/10/2019

This thread contains explanations and answers:

-- Yasen
Source: StackOverflow