在 kubernetes kubeconfig yaml 文件中渲染 env-var
rendering env-var inside kubernetes kubeconfig yaml file
我需要在我的 kubeconfig 文件中使用一个环境变量来指向 Kubernetes API 服务器的 NODE_IP
。
我的配置是:
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:
......
但是当我 运行 命令时,kubeconfig 文件似乎没有获取渲染变量:
kubectl --kubeconfig mykubeConfigFile get pods.
报错如下:
Unable to connect to the server: dial tcp: lookup $NODE_IP: no such host
有没有人尝试过这样的事情,或者有可能让它发挥作用吗?
提前致谢
这个thread包含解释和答案:
- ...要么wait Implement templates · Issue #23896 · kubernetes/kubernetes for the implementation of the templating proposal in
k8s
(not合并了)
- ... 或使用以下工具预处理您的 yaml:
envsubst
:
export NODE_IP="127.0.11.1"
envsubst < mykubeConfigFile.yml | kubectl --kubeconfig mykubeConfigFile.yml get pods
sed
:
cat mykubeConfigFile.yml | sed s/$$EXTERNAL_IP/127.0.11.1/ | kubectl --kubeconfig mykubeConfigFile.yml get pods
我需要在我的 kubeconfig 文件中使用一个环境变量来指向 Kubernetes API 服务器的 NODE_IP
。
我的配置是:
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:
......
但是当我 运行 命令时,kubeconfig 文件似乎没有获取渲染变量:
kubectl --kubeconfig mykubeConfigFile get pods.
报错如下:
Unable to connect to the server: dial tcp: lookup $NODE_IP: no such host
有没有人尝试过这样的事情,或者有可能让它发挥作用吗?
提前致谢
这个thread包含解释和答案:
- ...要么wait Implement templates · Issue #23896 · kubernetes/kubernetes for the implementation of the templating proposal in
k8s
(not合并了) - ... 或使用以下工具预处理您的 yaml:
envsubst
:
export NODE_IP="127.0.11.1" envsubst < mykubeConfigFile.yml | kubectl --kubeconfig mykubeConfigFile.yml get pods
sed
:
cat mykubeConfigFile.yml | sed s/$$EXTERNAL_IP/127.0.11.1/ | kubectl --kubeconfig mykubeConfigFile.yml get pods