【发布时间】:2019-02-15 18:18:34
【问题描述】:
对于我的 AKS 容器设置,我想通过环境变量将给定 statefulset 的请求数量的副本传递给每个 pod。
我试图在不重复自己的情况下执行此操作(一次在“副本”设置中,一次在环境变量设置中)。
我能找到的唯一真正的解决方案是使用锚和别名(基于Kubernetes StatefulSet - obtain spec.replicas metadata and reference elsewhere in configuration):
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: solr
spec:
selector:
matchLabels:
app: solr
serviceName: solr-hs
replicas: &numReplicas 3
updateStrategy:
type: RollingUpdate
# Make sure pods get created sequentially
podManagementPolicy: OrderedReady
template:
metadata:
labels:
app: solr
spec:
containers:
- name: kubernetes-solr
imagePullPolicy: Always
image: "..."
resources:
requests:
memory: "8Gi"
cpu: "0.5"
ports:
- containerPort: 8983
env:
- name: N_O_REPLICAS
value: *numReplicas
不幸的是,“env”值似乎必须是一个字符串,并且“replicas”的整数值不会被强制转换或转换。而是抛出以下错误:
v1.EnvVar.v1.EnvVar.Value: ReadString: 期望 " 或 n,但找到 3, 在 ...|,"value":3},{"name":|... 的 #10 字节中发现错误,更大 上下文 ...|:"solr-config"}}},{"name":"N_O_REPLICAS","value":3},
我尝试通过以下方式手动转换为字符串:
value: !!str *numReplicas
但这也不起作用并引发以下错误:
将 YAML 转换为 JSON 时出错:yaml: line 52: did not find expected key
有没有办法创建一个允许将整数值作为字符串重用的 Kubernetes YAML 文件?或者对于这种特殊情况有其他解决方案吗?
【问题讨论】:
标签: kubernetes yaml azure-aks kubernetes-statefulset