我正在为Kubernetes复制控制器规范添加一个环境变量,但是当我从规范更新正在运行的RC时,环境变量没有被添加到它。怎么样?
我根据以下规范更新RC,其中自上一版本以来添加了环境变量IRON_PASSWORD
,但运行的RC没有相应更新,kubectl replace -f docker/podspecs/web-controller.yaml
:
apiVersion: v1
kind: ReplicationController
metadata:
name: web
labels:
app: web
spec:
replicas: 1
selector:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: quay.io/aknuds1/muzhack
# Always pull latest version of image
imagePullPolicy: Always
env:
- name: APP_URI
value: https://staging.muzhack.com
- name: IRON_PASSWORD
value: password
ports:
- name: http-server
containerPort: 80
imagePullSecrets:
- name: quay.io
根据规范更新RC后,它看起来像这样(kubectl get pod web-scpc3 -o yaml
),注意到缺少IRON_PASSWORD:
apiVersion: v1
kind: Pod
metadata:
annotations:
kubernetes.io/created-by: |
{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicationController","namespace":"default","name":"web","uid":"c1c4185f-0867-11e6-b557-42010af000f7","apiVersion":"v1","resourceVersion":"17714"}}
kubernetes.io/limit-ranger: 'LimitRanger plugin set: cpu request for container
web'
creationTimestamp: 2016-04-22T08:54:00Z
generateName: web-
labels:
app: web
name: web-scpc3
namespace: default
resourceVersion: "17844"
selfLink: /api/v1/namespaces/default/pods/web-scpc3
uid: c1c5035f-0867-11e6-b557-42010af000f7
spec:
containers:
- env:
- name: APP_URI
value: https://staging.muzhack.com
image: quay.io/aknuds1/muzhack
imagePullPolicy: Always
name: web
ports:
- containerPort: 80
name: http-server
protocol: TCP
resources:
requests:
cpu: 100m
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-vfutp
readOnly: true
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: quay.io
nodeName: gke-staging-default-pool-f98acf11-ba7d
restartPolicy: Always
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes:
- name: default-token-vfutp
secret:
secretName: default-token-vfutp
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2016-04-22T09:00:49Z
message: 'containers with unready status: [web]'
reason: ContainersNotReady
status: "False"
type: Ready
containerStatuses:
- containerID: docker://dae22acb9f236433389ac0c51b730423ef9159d0c0e12770a322c70201fb7e2a
image: quay.io/aknuds1/muzhack
imageID: docker://8fef42c3eba5abe59c853e9ba811b3e9f10617a257396f48e564e3206e0e1103
lastState:
terminated:
containerID: docker://dae22acb9f236433389ac0c51b730423ef9159d0c0e12770a322c70201fb7e2a
exitCode: 1
finishedAt: 2016-04-22T09:00:48Z
reason: Error
startedAt: 2016-04-22T09:00:46Z
name: web
ready: false
restartCount: 6
state:
waiting:
message: Back-off 5m0s restarting failed container=web pod=web-scpc3_default(c1c5035f-0867-11e6-b557-42010af000f7)
reason: CrashLoopBackOff
hostIP: 10.132.0.3
phase: Running
podIP: 10.32.0.3
startTime: 2016-04-22T08:54:00Z
答案 0 :(得分:3)
替换ReplicationController对象实际上并不会重新创建基础pod,因此pod会保留规范来自RC的先前配置,直到需要重新创建它们为止。如果删除正在运行的pod,则创建的用于替换它的新pod将具有新的环境变量。
这是kubectl rolling update
command的用途,也是将Deployment类型添加到Kubernetes 1.2的部分原因。