我有一个 solr 容器,需要使用参数启动,无论是 master 还是 slave。我正在尝试将 env var 放入容器中,以便 init 脚本可以读取它,并以 master 或 slave 启动。
env:
- name: ROLE
value: "master"
容器启动,当我进入容器时,我可以看到 ROLE 变量已设置,但似乎初始化脚本没有选择它。
env var 是在 init 脚本运行之前还是之后设置的?如果是这样,我如何注入这个 var 以便脚本可以使用它?我宁愿不为这个小变量做 ConfigMap 或 Secret。
此容器已通过 Migrate for Anthos 从 EC2 转换为容器映像,并在 Anthos 集群中运行。
Dockerfile 示例,可重现
# Please refer to the documentation:
# https://cloud.google.com/migrate/anthos/docs/dockerfile-reference
FROM anthos-migrate.gcr.io/v2k-run-embedded:v1.8.1 as migrate-for-anthos-runtime
# Image containing data captured from the source VM
FROM mi5key/testing:v0.0.4
COPY --chown=root:root env-vars /etc/rc.d/init.d/env-vars
RUN /sbin/chkconfig env-vars on
COPY --from=migrate-for-anthos-runtime / /
ADD blocklist.yaml /.m4a/blocklist.yaml
ADD logs.yaml /code/config/logs/logsArtifact.yaml
# Migrate for Anthos image includes entrypoint
ENTRYPOINT [ "/.v2k.go" ]
部署规范.yaml
# Stateless application specification
# The Deployment creates a single replicated Pod, indicated by the 'replicas' field
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: env-vars-test
migrate-for-anthos-optimization: "true"
migrate-for-anthos-version: v1.8.1
name: env-vars-test
spec:
replicas: 1
selector:
matchLabels:
app: env-vars-test
migrate-for-anthos-optimization: "true"
migrate-for-anthos-version: v1.8.1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: env-vars-test
migrate-for-anthos-optimization: "true"
migrate-for-anthos-version: v1.8.1
spec:
containers:
- image: docker.io/mi5key/testing:v0.0.4
imagePullPolicy: IfNotPresent
name: env-vars-test
readinessProbe:
exec:
command:
- /code/ready.sh
resources:
limits:
memory: "1Gi"
cpu: "1"
env:
- name: ROLE
value: "single"
securityContext:
privileged: true
volumeMounts:
- mountPath: /sys/fs/cgroup
name: cgroups
volumes:
- hostPath:
path: /sys/fs/cgroup
type: Directory
name: cgroups
status: {}