kubernetes学习---记录一次pod迁移到指定node
kubernetes学习---记录一次pod迁移到指定node
·
二十、kubernetes学习—记录一次pod迁移到指定node
目前三个项目的pod随机分布在各节点上运行,如图
现需要将这三个项目的pod迁移到**k8s-100-55、k8s-100-56**两个节点上
你可以约束一个 Pod 只能在特定的 Node(s) 上运行,或者优先运行在特定的节点上。有几种方法可以实现这点,推荐的方法都是用标签选择器(nodeSelector)来进行选择。通常这样的约束不是必须的,因为调度器将自动进行合理的放置(比如,将 pod 分散到节点上,而不是将 pod 放置在可用资源不足的节点上等等),但在某些情况下,你可以需要更多控制 pod 停靠的节点,例如,确保 pod 最终落在连接了 SSD 的机器上,或者将来自两个不同的服务且有大量通信的 pod 放置在同一个可用区。
1、查看愿node的标签
# 查看愿node的标签
kubectl get node --show-labels
1、给节点打上标签
# 给node节点打上project=true的标签
kubectl label nodes k8s-100-55.host.com project=true
kubectl label nodes k8s-100-56.host.com project=true
2、把pod部署到指定标签(project=true)的节点
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: project-system
name: project-system
namespace: kubernetes
spec:
replicas: 1
selector:
matchLabels:
app: project-system
namespace: kubernetes
spec:
replicas: 1
selector:
matchLabels:
app: project-system
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: project-system
spec:
affinity:
metadata:
creationTimestamp: null
labels:
app: project-system
spec:
nodeSelector: # 此处添加nodeSelector
project: true
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- project-system
topologyKey: kubernetes.io/hostname
weight: 100
containers:
- env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: C.UTF-8
image: harbor.xuexi.com/public/nginx:latest
imagePullPolicy: IfNotPresent
lifecycle: {}
livenessProbe:
failureThreshold: 2
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 82
timeoutSeconds: 2
name: project-system
ports:
- containerPort: 82
name: web
protocol: TCP
readinessProbe:
failureThreshold: 2
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 82
timeoutSeconds: 2
resources:
limits:
cpu: 994m
memory: 1170Mi
requests:
cpu: 10m
memory: 55Mi
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: harborkey
restartPolicy: Always
securityContext: {}
serviceAccountName: default
迁移成功后
更多推荐
已为社区贡献8条内容
所有评论(0)