Openshift - 环境变量被评估为主机名

Openshift - Environment variable getting evaluated to hostname

我想传递一个环境变量,该变量应该被评估为 运行 容器的主机名。这就是我想要做的

oc new-app -e DASHBOARD_PROTOCOL=http -e ADMIN_PASSWORD=abc@123 -e KEYCLOAK_URL=http://keycloak.openidp.svc:8080 -e KEYCLOAK_REALM=master -e DASHBOARD_HOSTNAME=$HOSTNAME -e GF_INSTALL_PLUGINS=grafana-simple-json-datasource,michaeldmoore-annunciator-panel,briangann-gauge-panel,savantly-heatmap-panel,briangann-datatable-panel grafana/grafana:5.2.1

如何确保 DASHBOARD_HOSTNAME 被评估为 运行 容器映像的主机名的值

创建应用程序后,您可以编辑部署配置 (oc edit dc/<deployment_config>) 或 patch it to configure the DASHBOARD_HOSTNAME environment variable using the Downward API

这可能是个人喜好,但尽管 oc new-app 很方便,但我更愿意使用 (declarative) configuration files that are checked in and versioned in a code repo than with imperative commands.

要从 pod 中获取主机名值,您可以使用 metadata.name。 按照例如:

  env:
    - name: HOSTNAME
      valueFrom:
        fieldRef:
          apiVersion: v1
          fieldPath: metadata.name