2

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

Amit Kumar Gupta
  • 17,184
  • 7
  • 46
  • 64
oguz
  • 514
  • 4
  • 9
  • You can do `kubectl --kubeconfig mykubeConfigFile --server "https://${NODE_IP}:6443" get pods`. Read more about kubeconfig [here](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) – Amit Kumar Gupta Sep 10 '19 at 18:33
  • @Amit thanks a lot for the response and editing my post, but I think helm is not supporting the --server option. I share my output of helm command below. Error: unknown flag: --server But anyway I dont know how happened but my problem is solved. I am able to upload helmchart within the pod with deafult kubeconfig configuration. So I didnt have to pass the new kubeconfig file anyway. – oguz Sep 12 '19 at 11:17

1 Answers1

3

This thread contains explanations and answers:

Yasen
  • 4,241
  • 1
  • 16
  • 25
  • thx for the suggestion. As I described I didnt have to pass kubeconfig file to the command finally. I have no idea why. But if i needed again envsubst is a solid solution i missed it. – oguz Sep 12 '19 at 11:22