azure - 将 ado 变量传递给 Azure ADO 上的 pv、pvc、配置映射和部署文件

标签 azure kubernetes azure-devops azure-aks

我有一个要求,需要在 AKS 上安装 20 多个 Azure Blob 容器。如果我手动的话,我可以通过为 pv 和 pvc 编写 40 多个文件来实现。我创建了一个 DevOps 管道,其中多个变量文件中包含所有 pv 和 pvc 详细信息,并希望将它们传递到创建 pv 和 pvc 的 yaml 文件。

variables:
  volume_name: container1-pv
  pvc_name: container1-pvc
  config_map_name: container1-cm
  deployment: log_container1
  volume_handle: container1handle

我将创建多组这些变量来安装它们。

现在我想将这些变量传递给 pv yaml 文件。

kind: PersistentVolume
apiVersion: v1
metadata:
  name: container1-pv # this is where I want to substitute the variable
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain  # If set as "Delete" container would be removed after pvc deletion
  mountOptions:
    - -o allow_other
    - --file-cache-timeout-in-seconds=30
  csi:
    driver: blob.csi.azure.com
    readOnly: false
    # make sure this volumeid is unique in the cluster
    # `#` is not allowed in self defined volumeHandle
    volumeHandle: container1-hande # one more place to substitute 
    volumeAttributes:
      containerName: container1 # one more place to substitute 
    nodeStageSecretRef:
      name: azure-secret
      namespace: logs

我在 ADO 中给出的用于创建 pv 的命令。

kubectl create -f Pv/logs-pv.yml -n diag-logs

请告知如何实现这一目标。

最佳答案

您可以使用 Helm 模板 选项循环访问存储数据的单个文件,并且您可以创建 YAML 文件。

Helm 模板

{{- $volumes := .Values.variables }}
{{- range $volumes }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: {{ .pvc_name }}
  labels:
    name: {{ .volume_name }}
spec:
  name: {{ .volume_name }}
  csi:
    volumeHandle: {{ .volume_name }}
    volumeAttributes:
      containerName: {{ .deployment }}
{{- end }}

values.yaml

variables:
  - volume_name: container1-pv
    pvc_name: container1-pvc
    config_map_name: container1-cm
    deployment: log_container1
    volume_handle: container1handle
  - volume_name: container2-pv
    pvc_name: container2-pvc
    config_map_name: container2-cm
    deployment: log_container2
    volume_handle: container2handle

关于azure - 将 ado 变量传递给 Azure ADO 上的 pv、pvc、配置映射和部署文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76363767/

相关文章:

kubernetes - 为什么 Kubernetes 部署 YAML 文件如此重复?

c# - 具有 HTTP 触发器的 Azure 函数在开始处理之前返回 "received"消息

Azure 应用服务 - ARR 亲和性 - 自动缩放 - 有状态应用程序

azure - KQL - 基于特定列限制数据量

azure - 如何在 azure devops YAML 管道中使用单个代理执行多个作业/阶段

version-control - 是否可以在不使用 Visual Studio 或其他 IDE 的情况下使用 VS Team Services 进行源代码控制?

npm - 使用 package.json 中的内部版本号

c# - 在 Owin 中针对 Power Bi 进行身份验证

生产中的 Kubernetes。工作 Pod 出现问题

kubernetes - 如何限制来自kubernetes内部pod的外部服务中的源IP