簡體   English   中英

在 k8s 中部署 Redis 時使用 args 設置 requirepass 適用於 $() 但不適用於 ${}

[英]Setting requirepass with args while deploying Redis in k8s works with $() but not with ${}

我正在嘗試將 Redis (通過創建 Helm 圖表)部署為 Kubernetes 集群中的 StatefulSet。 I am not creating another Redis image on top of Official Redis Docker image, rather I am just trying to use the defaults available in Official Redis Docker image and just provide my redis.conf and requirepass at runtime.

為了提供redis.conf ,我使用 ConfigMap 並將其安裝在容器的/config/redis.conf中。

現在,我想在 Kubernetes --requirepass選項作為args傳遞,如下所示:

...
containers: [
  {
    name: redis,
    image: {
      repository: redis,
      tag: 5.0
    },
    imagePullPolicy: Always,
    workingDir: /data/,
    args: [ "/config/redis.conf", "--requirepass", "<password>" ],  # line of concern
    ports: [
      containerPort: 6379
    ],
    env: [
      {
        name: REDIS_AUTH,
        valueFrom: {
          secretKeyRef: {
            name: redis,
            key: password
          }
        }
      }
    ],
...

以下行失敗:

args: [ "/config/redis.conf", "--requirepass", "${REDIS_AUTH}" ]

相反,這有效:

args: [ "/config/redis.conf", "--requirepass", "$(REDIS_AUTH)" ]

即使$()語法用於命令替換, REDIS_AUTH是環境變量而不是可執行文件,它是如何工作的,而${REDIS_AUTH}不是?

這是 Kubernetes 的特定功能,如果您想在commandargs字段中擴展環境變量,那么您必須使用$()語法而不是${}語法。

檢查此鏈接: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#use-environment-variables-to-define-arguments

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM