ᕕ( ᐛ )ᕗ Jimyag's Blog

k8s 将 pod 调度到指定节点上

先给 节点打上标签

1
kubectl label nodes node-1 node-role.kubernetes.io/some-role=

在 deployment 中使用 nodeSelector 进行过滤

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# test-node-selector.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/instance: test
    app.kubernetes.io/name: example
  name: test-node-selector
  namespace: default
spec:
  replicas: 1 
  selector:
    matchLabels:
      app.kubernetes.io/instance: test
      app.kubernetes.io/name: example
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: test
        app.kubernetes.io/name: example
    spec:
      containers:
        - args:
            - |
              sleep 100;
              echo hell0;
          command:
            - /bin/bash
            - -c
          image: busybox:latest
          imagePullPolicy: IfNotPresent
          name: busybox
          resources:
            limits:
              cpu: "1"
              memory: "6G"
            requests:
              cpu: "1"
              memory: "30Mi"
      nodeSelector:
        node-role.kubernetes.io/some-role: ""
1
kubectl apply -f test-node-selector.yaml

#K8s