某些特殊情况下,需要将某些服务固定在一台宿主机上,K8S也适应这种方式,下面以mongo为例,来看看如何实现的:
kubectl label nodes kube-node node=kube-node
kubectl get node -a -l "node=kube-node"
pod或者rc的配置项中添加如下配置:
nodeSelector:
node: kube-node4
如mongo启动的rc文件
apiVersion: v1
kind: ReplicationController
metadata:
name: mongo
spec:
replicas: 1
template:
metadata:
labels:
run: mongo
spec:
containers:
- name: mongo
image: daocloud.io/library/mongo:3.2.4
ports:
- containerPort: 27017
volumeMounts:
- mountPath: /data/db
name: mongo
volumes: [{"name":"mongo","hostPath":{"path":"/root/volumes/mongo"}}]
nodeSelector:
node: kube-node4
by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(==防止爬虫==):http://blog.liuyingguang.cn