具有两个不同图像的DaemonSet.但只能使用其中一个



我想要实现的目标:假设我有一个由20个工作节点组成的物理集群,客户希望向DaemonSet推出新版本的docker映像。但是,客户不想推广到整个集群,他们只想将更新专用于3个节点";飞行员;节点。我们使用龙骨自动更新图像。有没有一种方法可以用新的图像来更新这些导频;旧的";形象

我们有一个具有DeamonSet的k8s集群,该DeamonSet具有nodeSelector=worker;安装";带有特定容器的吊舱。我不知道如果不使用两个不同的DeamonSets,我怎么能做到这一点。这个问题有什么解决办法吗。

我真的不知道如何解决这个问题,我已经在互联网上搜索了一些解决方案。但什么也找不到。

您可以对守护进程集(docs(使用OnDelete更新策略:

使用OnDelete更新策略,在更新DaemonSet模板后,只有手动删除旧的DaemonSet pod时,才会创建新的DaemotSet podDaemonSet吊舱。

因此,您可以手动删除试点节点上的pod,kubernetes将重新部署具有新映像的pod。这有一些缺点;非飞行员";节点在重新启动的同时,它也会得到新的映像,并且涉及到一些手动步骤。

另一种方法是部署具有不同映像的两个守护程序集,标记引导节点,并让具有新映像的守护程序集仅部署到引导节点,而旧映像仅部署到非引导节点(通过nodeaffinity(。例如

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: new-version
spec:
selector:
matchLabels:
- image: image:new-version
name: ...
template:
metadata:
labels:
name: new-version
spec:
containers:
- name: ...
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: my-pilot-node-label
operator: Exists

而";旧的";后台进程集:

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: old-version
spec:
selector:
matchLabels:
name: old-version
template:
metadata:
labels:
name: old-version
spec:
containers:
- image: image:olb-version
name: ...
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: my-pilot-node-label
operator: DoesNotExist

对于需要保留一个守护程序集的情况,解决方案可能是在守护程序集中的pod中运行两个容器,并根据节点名称决定哪个容器实际运行映像上的原始入口点,而另一个容器则只运行一个空闲循环。

即使这或多或少是一个";"黑客">解决方案,而不是sidecar容器的设计目的,它可能符合目的。

注意:这个解决方案的一个缺点是不能在两个容器上公开相同的端口。如果您需要公开一个端口,那么您需要在不同的端口上公开它们,并运行第三个容器,该容器公开原始端口,并将一些端口转发到localhost,分别转发到生产端口(试点容器(。

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: canary-daemon-set
spec:
selector:
matchLabels:
uuid: "bd960882-5532-11ed-9bbb-3fa21b1d20ae"
template:
metadata:
labels:
uuid: "bd960882-5532-11ed-9bbb-3fa21b1d20ae"
spec:
containers:
- name: production
image: bash:5.1
command:
- bash
- -c
# run entry point as defined in image, if run on production nodes (decide based
# on node name and selected pilot nodes whether to run the entrypoint according
# the image or an idle-loop)
- if echo $PILOT_NODES | grep -w -q $NODE_NAME; then echo not starting, this is a pilot node; while true; do sleep 10; done; else bash --version; echo run original command here; while true; do sleep 10; done; fi
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: PILOT_NODES
value: "worker18 worker19 worker20"
- name: pilot
image: bash:5.2
command:
- bash
- -c
# run entry point as defined in image, if run on pilot nodes (decide based
# on node name and selected pilot nodes whether to run the entrypoint according
# the image or an idle-loop)
- if ! echo $PILOT_NODES | grep -w -q $NODE_NAME; then echo not starting, this is a pilot node; while true; do sleep 10; done; else bash --version; echo run original command here; while true; do sleep 10; done; fi
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: PILOT_NODES
value: "worker18 worker19 worker20"

最新更新