Kubernetes:如何配置要在同一节点上部署的一组Pod? [英] Kubernetes: How to config a group of pods to be deployed on the same node?

查看:123
本文介绍了Kubernetes:如何配置要在同一节点上部署的一组Pod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例是这样的:

因此,我们有几个Pod使用相同的persistentVolumeClaim,并且accessMode设置为ReadWriteOnce(因为PersistentVolume的存储类仅支持ReadWriteOnce).

So we have several pods using the same persistentVolumeClaim with the accessMode set to ReadWriteOnce (because the storage class of the PersistentVolume only support ReadWriteOnce).

来自 https://kubernetes.io/docs/concepts/storage/persistent -volumes/

ReadWriteOnce -- the volume can be mounted as read-write by a single node

因此,应将这些Pod部署在同一节点上,以便访问PVC(否则它们将失败).

So these pods should be deployed on the same node in order to access the PVC (otherwise they will fail).

我想问一下是否有任何方法可以配置yaml部署文件,以便可以将它们部署在同一节点上?或有什么方法可以解决这个问题?

I would like to ask if there are any ways to config the deployment yaml file so that they can be deployed on the same node? or are there any ways to solve this problem?

推荐答案

有了Chin提出的豆荚间亲和力解决方案,我得以解决该问题:

With the inter-pod affinity solution as suggested by Chin, I was able to solve the problem:

以下是我的Deployment yaml文件:

The following is my Deployment yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-go
  namespace: stage
  labels:
    app: test-go
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-go
  template:
    metadata:
      labels:
        app: test-go
        service: git
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: service
                operator: In
                values:
                - git
            topologyKey: kubernetes.io/hostname
      containers:
      - name: test-go
        image: registry.gitlab.com/xxxxxxx/test-go
      imagePullSecrets:
        - name: registry-pull-secret

Deployment yaml文件中,在pod模板spec.template.metadata.labels中设置标签,然后根据添加的标签添加podAffinity config,将topologyKey设置为kubernetes.io/hostname,以便将Pod部署在同一节点上.

In the Deployment yaml file, set a label in the pod template spec.template.metadata.labels, and then add podAffinity config based on the label added, set topologyKey to kubernetes.io/hostname so that the pods will be deployed on the same node.

这篇关于Kubernetes:如何配置要在同一节点上部署的一组Pod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆