Search code examples
kubernetesyamlkubeconfig

rendering env-var inside kubernetes kubeconfig yaml file


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


Solution

  • This thread contains explanations and answers: