我需要在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.
它抱怨如下:
无法连接到服务器:拨打tcp:查找$ NODE_IP:没有这样的主机
有人试图做这样的事情还是有可能使其起作用?
预先感谢
答案 0 :(得分:2)
此thread包含说明和答案:
k8s
中wait的Implement templates · Issue #23896 · kubernetes/kubernetes的the implementation of the templating proposal(not已合并)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