如何在petset中指定nodeSelector?

时间:2016-12-16 07:32:28

标签: kubernetes

我正在尝试部署类似于此页面中给出的示例的PetSet。http://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/

完整的yaml -

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: gcr.io/google_containers/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
      annotations:
        volume.alpha.kubernetes.io/storage-class: anything
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

但我需要pods才能转到特定节点。我已将节点标记为 -

kubectl label nodes 10.XX.XX.XX node-type=nginx-0

如何在yaml上面指定nodeSelector?

1 个答案:

答案 0 :(得分:0)

containers规范下添加

spec:
  containers:
    - name: nginx
    image: gcr.io/google_containers/nginx-slim:0.8
    ports:
      - containerPort: 80
        name: web
      volumeMounts:
      - name: www
        mountPath: /usr/share/nginx/html
  nodeSelector:
    node-type: nginx-0