ᕕ( ᐛ )ᕗ Jimyag's Blog

k8s 将 pod 调度到指定节点上

先给 节点打上标签

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

在 deployment 中使用 nodeSelector 进行过滤

# 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: ""
kubectl apply -f test-node-selector.yaml

#k8s