在不可抢占的节点上运行有状态集?

时间:2018-09-12 13:35:12

标签: kubernetes google-cloud-platform google-kubernetes-engine

我正在尝试在其中具有可抢占节点的Kubernetes集群上运行StatefulSet,但是我不想在可抢占节点上运行StatefulSet,因为它们最多可使用24小时。

如本post中所述,我们可以通过以下部署/吊舱来做到这一点:

affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: cloud.google.com/gke-preemptible
          operator: DoesNotExist 

但是我应该如何在有状态集上做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以在规范定义中使用它,就像在部署中一样:

示例:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 3 # by default is 1
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
           - matchExpressions:
              - key: cloud.google.com/gke-preemptible
                operator: DoesNotExist
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi