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:在PersistentVolume主机路径中使用环境变量/ConfigMap_Kubernetes_Configmap - Fatal编程技术网

Kubernetes:在PersistentVolume主机路径中使用环境变量/ConfigMap

Kubernetes:在PersistentVolume主机路径中使用环境变量/ConfigMap,kubernetes,configmap,Kubernetes,Configmap,有人知道是否可以在PersistentVolume的hostPath中使用环境变量或ConfigMap吗?发现可以使用Helm、envsubst等,但我只想使用Kubernetes函数 我需要创建一个非静态路径的卷 这是我的PV: apiVersion:v1 种类:PersistentVolume 元数据: 姓名:某pv 标签: 类型:本地 规格: storageClassName:手动 容量: 存储:2Gi 访问模式: -读写 主机路径: 路径:“${path\u FROM\u ENV}/so

有人知道是否可以在PersistentVolume的hostPath中使用环境变量或ConfigMap吗?发现可以使用Helm、envsubst等,但我只想使用Kubernetes函数

我需要创建一个非静态路径的卷

这是我的PV:

apiVersion:v1 种类:PersistentVolume 元数据: 姓名:某pv 标签: 类型:本地 规格: storageClassName:手动 容量: 存储:2Gi 访问模式: -读写 主机路径: 路径:“${path\u FROM\u ENV}/some path”
您不能以本机方式执行此操作,但从configmap读取的kubernetes作业组合可以为您执行此操作。 我们将创建一个具有适当RBAC权限的作业,此作业使用kubectl映像,读取configmap,并将其传递给PV创建清单

以下是舱单:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  namespace: default
  name: pv-generator-role
rules:
- apiGroups: [""] # "" indicates the core API group
  resources: ["persistentvolumes"]
  verbs: ["create"]
- apiGroups: [""] # "" indicates the core API group
  resources: ["configmaps"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: pv-geneartor-role-binding
  namespace: default
subjects:
- kind: ServiceAccount
  name: pv-generator-sa
  namespace: default
roleRef:
  kind: ClusterRole
  name: pv-generator-role
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: pv-generator-sa
---
apiVersion: batch/v1
kind: Job
metadata:
  name: pv-generator
spec:
  template:
    spec:
      serviceAccountName: pv-generator-sa
      containers:
      - name: kubectl
        image: bitnami/kubectl
        command: 
        - sh
        - "-c"
        - |
          /bin/bash <<'EOF'
          cat <<EOF | kubectl apply -f -
          apiVersion: v1
          kind: PersistentVolume
          metadata:
            name: some-pv
            labels:
              type: local
          spec:
            storageClassName: manual
            capacity:
              storage: 2Gi
            accessModes:
              - ReadWriteOnce
            hostPath:
              path: $(kubectl get cm path-configmap -ojsonpath="{.data.path}")/some-path
          EOF
      restartPolicy: Never
  backoffLimit: 4
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: path-configmap
  namespace: default
data:
  path: /mypath
apiVersion:rbac.authorization.k8s.io/v1 种类:ClusterRole 元数据: 名称空间:默认值 名称:光伏发电机角色 规则: -apiGroups:[“”]#“”表示核心API组 资源:[“persistentvolumes”] 动词:[“创建”] -apiGroups:[“”]#“”表示核心API组 资源:[“配置映射”] 动词:[“get”] --- apiVersion:rbac.authorization.k8s.io/v1 种类:簇状卷边 元数据: 名称:pv geneartor角色绑定 名称空间:默认值 学科: -种类:服务帐户 名称:光伏发电机sa 名称空间:默认值 roleRef: 种类:ClusterRole 名称:光伏发电机角色 apiGroup:rbac.authorization.k8s.io --- 版本:v1 种类:服务帐户 元数据: 名称:光伏发电机sa --- apiVersion:batch/v1 种类:工作 元数据: 名称:光伏发电机 规格: 模板: 规格: 服务帐户名称:光伏发电机sa 容器: -姓名:kubectl 图片:bitnami/kubectl 命令: -嘘 -“-c” - | /bin/bash