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

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

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

就像在post中提到的,我们可以使用Deployments / Pod来做到这一点:

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

但是我应该如何在有状态集上执行此操作?

最佳答案

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

例:

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

关于kubernetes - 在不可抢占的节点上运行有状态集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52296517/

相关文章:

Kubernetes - 从作业连接到 cassandra 到不同的 pod

kubernetes - 如何使用 kubectl scale 在不同节点上调度相同的 pod?

google-cloud-platform - 是否可以删除命名空间内的所有 Google Cloud 数据存储类型?

kubernetes - 为什么kubernetes OOM会杀死一个暂停容器?

apache-spark - 我们能否仅在 GKE 或私有(private)本地 k8s 上运行 Dataproc?

kubernetes - 是否可以使用kubernetes_config_map资源--from-file ConfigMap?

nginx - 使用Nginx-ingress从外部kubernetes集群向RabbitMQ发送消息

google-cloud-platform - 谷歌云计费API,抓取当月费用

machine-learning - GCP - 创建数据流(Pub/Sub -> 预测(ML 模型) -> BigQuery/Firebase)

kubernetes - 将 GKE 服务帐户凭据与 kubectl 结合使用