【问题标题】:How to have pod replica specific property file in Kubernetes?如何在 Kubernetes 中拥有 pod 副本特定的属性文件?
【发布时间】:2022-09-23 02:07:20
【问题描述】:

我正在容器化 kubernetes 上的 spring-boot 应用程序,我希望为每个 POD 副本拥有一个不同的应用程序属性文件。 因为我想为不同的 pod 副本提供不同的配置。

上述任何帮助将不胜感激。

    标签: kubernetes containers kubernetes-pod


    【解决方案1】:

    如果您想为每个 pod 提供唯一的配置,它们并不是真正的复制品。我想您可能正在寻找StatefulSet。引用文档:

    与 Deployment 类似,StatefulSet 管理基于相同容器规范的 Pod。与 Deployment 不同,StatefulSet 为其每个 Pod 维护一个粘性标识。这些 pod 是根据相同的规范创建的,但不可互换:每个 pod 都有一个持久标识符,它在任何重新调度时都会维护该标识符。

    例如,给定这样的 StatefulSet:

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: example
    spec:
      selector:
        matchLabels:
          app: example
      serviceName: "example"
      replicas: 3
      template:
        metadata:
          labels:
            app: example
        spec:
          containers:
          - name: nginx
            image: docker.io/nginxinc/nginx-unprivileged:mainline
            ports:
            - containerPort: 80
              name: http
    

    我最终得到:

    $ kubectl get pod
    NAME        READY   STATUS    RESTARTS   AGE
    example-0   1/1     Running   0          34s
    example-1   1/1     Running   0          31s
    example-2   1/1     Running   0          28s
    

    在每个 pod 中,我可以查看 $HOSTNAME 的值以找到我的唯一名称,我可以使用它从目录路径/结构化文件/等中提取适当的配置。

    【讨论】:

      猜你喜欢
      • 2018-07-05
      • 1970-01-01
      • 2021-06-26
      • 2018-10-09
      • 2018-12-16
      • 1970-01-01
      • 2017-06-22
      • 2018-12-16
      • 1970-01-01
      相关资源
      最近更新 更多