Kubernetes:如何配置要部署在同一节点上的一组吊舱?

Kubernetes:如何配置要部署在同一节点上的一组吊舱?,kubernetes,persistent-volumes,persistent-volume-claims,Kubernetes,Persistent Volumes,Persistent Volume Claims,用例如下所示: 因此,我们有几个pod使用相同的persistentVolumeClaim,accessMode设置为ReadWriteOnce(因为PersistentVolume的存储类只支持ReadWriteOnce) 从 因此,这些POD应该部署在同一个节点上,以便访问PVC(否则它们将失败) 我想问一下,是否有任何方法可以配置部署yaml文件,以便它们可以部署在同一个节点上?或者有什么方法可以解决这个问题吗?Chin aready提到过,这是一个有效的解决方案,但我想再提一个解决方案,

用例如下所示:

因此,我们有几个pod使用相同的
persistentVolumeClaim
accessMode
设置为
ReadWriteOnce
(因为
PersistentVolume
的存储类只支持
ReadWriteOnce

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

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

Chin aready提到过,这是一个有效的解决方案,但我想再提一个解决方案,可能有点争议,但在同样的情况下仍然有效

如果您必须在一个节点上运行所有容器,您可以将所有这些容器放在一个pod中,它们将始终一起运行,最重要的是,您可以毫无困难地将持久卷装载到该节点上。只需记住,过度使用被认为是不好的做法;总是喜欢每个吊舱一个容器而不是每个吊舱多个容器,虽然您的用例可能是该规则的一个例外,但我很难说,因为我对这些吊舱一无所知


阅读更多关于

的信息,如Chin所建议的,使用荚间亲和性解决方案,我能够解决问题:

以下是我的
部署
yaml文件:

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
中设置一个标签,然后根据添加的标签添加
podaaffinity
config,将
topologyKey
设置为
kubernetes.io/hostname
,这样吊舱将部署在同一个节点上。

你知道吗?谢谢@ChinHuang的启发,我试图实现它,但遇到了一些问题,你能检查我的新问题吗:谢谢@matt的输入,这听起来很合理,并且可以是一种选择。但是我会先尝试一下pod间的关联性,当然,只是想涵盖所有选项:实际上,在一个pod中同时部署不同项目中的三个不同容器并不容易,我还没有想到处理CI和部署脚本的方法。
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