Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes 用一些环境变量替换configmap内容_Kubernetes_Configmap_Kubernetes Statefulset - Fatal编程技术网

Kubernetes 用一些环境变量替换configmap内容

Kubernetes 用一些环境变量替换configmap内容,kubernetes,configmap,kubernetes-statefulset,Kubernetes,Configmap,Kubernetes Statefulset,我正在运行一个statefolset,其中我使用volumeClaimTemplates。那里一切都很好 我还有一个configmap,在这里我想用这个配置文件投影到的每个pod的pod名称替换一些条目;例如,如果configmap数据为: ThisHost=<hostname -s> OtherConfig1=1 OtherConfig1=2 ... 此主机= OtherConfig1=1 OtherConfig1=2 ... 然后,对于名为mypod-0的状态集pod,配置文

我正在运行一个statefolset,其中我使用volumeClaimTemplates。那里一切都很好

我还有一个configmap,在这里我想用这个配置文件投影到的每个pod的pod名称替换一些条目;例如,如果configmap数据为:

ThisHost=<hostname -s>
OtherConfig1=1
OtherConfig1=2
...
此主机=
OtherConfig1=1
OtherConfig1=2
...
然后,对于名为
mypod-0
的状态集pod,配置文件应包含
thishhost=mypod-0
thishhost=mypod-1
mypod-1


我该怎么做呢?

主机名包含在pod内的环境变量中,默认情况下称为
HOSTNAME
。 如果您首先:

  • 装载configmap并将其设置为
    thishhost=hostname-s
    (这将在pod的文件系统中创建一个包含该文本的文件)
  • 启动时向pod传递替换命令(类似于
    $sed's/hostname/$hostname/g'-i/path/to/configmapfile
基本上,您装载configmap,然后用pod中可用的环境变量信息替换它。这只是一个替换操作

请看下面的示例:

apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
purpose: demonstrate-command
spec:
containers:
- name: command-demo-container
image: debian
command: ["sed"]
args: ["'s/hostname/$HOSTNAME'", "-i", "/path/to/config/map/mount/point"]
restartPolicy: OnFailure
args的语法可能需要一些调整,但您已经明白了


如果有帮助,请告诉我

主机名包含在pod内的环境变量中,默认情况下称为
HOSTNAME
。 如果您首先:

  • 装载configmap并将其设置为
    thishhost=hostname-s
    (这将在pod的文件系统中创建一个包含该文本的文件)
  • 启动时向pod传递替换命令(类似于
    $sed's/hostname/$hostname/g'-i/path/to/configmapfile
基本上,您装载configmap,然后用pod中可用的环境变量信息替换它。这只是一个替换操作

请看下面的示例:

apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
purpose: demonstrate-command
spec:
containers:
- name: command-demo-container
image: debian
command: ["sed"]
args: ["'s/hostname/$HOSTNAME'", "-i", "/path/to/config/map/mount/point"]
restartPolicy: OnFailure
args的语法可能需要一些调整,但您已经明白了

如果有帮助,请告诉我