我正在尝试从这个链接安装RabbitMQ操作符在K8S集群
我在我们的环境
上创建了以下设置
例子K8S Control Plane (Cent OS) - 192.168.1.2
Worker Node - 1 (Cent OS) - 192.168.1.3
Worker Node - 2 (WindowS) - 192.168.1.4
当我默认执行kubectl apply -f https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml
时,它会尝试安装RabbitMQ on Windows Node
由于RabbitMQ操作符YAML文件太大,我不确定在哪里和所有nodeSelector应该更改
然而,我想安装RabbitMQ on Linux node
,我不知道如何更改/设置Kubernetes的默认节点
编辑
[root@re-ctrl1 ~]# kubectl get nodes -o wide --show-labels
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME LABELS
re-devcentos Ready <none> 83d v1.21.0 192.168.1.3 <none> CentOS Linux 7 (Core) 3.10.0-862.el7.x86_64 docker://1.13.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=re-devcentos,kubernetes.io/os=linux
re-ctrl1 Ready control-plane,master 91d v1.21.0 192.168.1.2 <none> CentOS Linux 7 (Core) 3.10.0-862.el7.x86_64 docker://20.10.6 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=re-ctrl1,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers=
win-lj7gtbktpgg Ready <none> 8d v1.21.1 192.168.1.4 <none> Windows Server 2019 Standard 10.0.17763.2061 docker://20.10.7 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=windows,kubernetes.io/arch=amd64,kubernetes.io/hostname=win-lj7gtbktpgg,kubernetes.io/os=windows,node.kubernetes.io/windows-build=10.0.17763
在您的node
标签中,有一个有用的标签称为kubernetes.io/os=linux
,您应该使用此标签来调度节点上的pod。
例如:(部分文件)....
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/component: rabbitmq-operator
app.kubernetes.io/name: rabbitmq-cluster-operator
app.kubernetes.io/part-of: rabbitmq
name: rabbitmq-cluster-operator
namespace: rabbitmq-system
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: rabbitmq-cluster-operator
template:
metadata:
labels:
app.kubernetes.io/component: rabbitmq-operator
app.kubernetes.io/name: rabbitmq-cluster-operator
app.kubernetes.io/part-of: rabbitmq
spec:
nodeSelector:
kubernetes.io/os: linux #<----this is making deployment's pod to choose node with this label.
containers:
- command:
- /manager
env:
- name: OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: rabbitmqoperator/cluster-operator:1.8.0
name: operator
ports:
您可以使用相同的多个选项,您可以使用节点选择器,节点关联&taint-toleration .
节点亲缘性是pod的一种属性,它将它们吸引到一组节点(作为首选项或硬性要求)。污点则相反——它们允许节点排斥一组pod。
https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/affinity-and-anti-affinity
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/e2e-az-name
operator: In
values:
- e2e-az1
- e2e-az2
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
containers:
- name: with-node-affinity
image: k8s.gcr.io/pause:2.0
对于rabbitMQ,它可以像
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: rabbitmq
spec:
replicas: 1
serviceName: rabbitmq
selector:
matchLabels:
app: rabbitmq
template:
metadata:
labels:
app: rabbitmq
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
- ubuntu
containers:
- name: rabbitmq
image: rabbitmq:3-management
env:
- name: "RABBITMQ_ERLANG_COOKIE"
value: "dsfsadfsfsd+0t36lQ="
volumeMounts:
- mountPath: /var/lib/rabbitmq
name: rabbitmq-data
volumes:
- name: rabbitmq-data
hostPath:
path: /data/rabbitmq
type: DirectoryOrCreate
污点,容错示例:https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/