【问题标题】:Getting fully_qualified_digest into yaml for deploy将 fully_qualified_digest 放入 yaml 进行部署
【发布时间】:2019-08-21 23:42:04
【问题描述】:

我们有一个 GKE 集群,其中包含 4 个部署/pod,当我们部署新代码时需要更新这些部署/pod。我知道使用我们正在部署的图像的最新摘要部署图像是最佳实践,但我想知道是否有人知道使用该摘要更新 yaml 文件的更好方法,而不是手动更新它。我可以使用以下方法获得fully_qualified_digest:

gcloud container images describe gcr.io/xxxx/uwsgi

每次部署时都必须使用最新的摘要哈希手动更新 yaml 文件,这真的很糟糕。如果有人知道更好的方法,我很乐意听到。

旁注:现在是 2019 年,Kubernetes 应该能够获取摘要哈希形式 /latest 而无需明确定义它。

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: uwsgi
  name: uwsgi
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  minReadySeconds: 5
  template:
    metadata:
      labels:
        io.kompose.service: uwsgi
    spec:
      containers:
      - env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: certs/gcp.json
        - name: ENV
          value: prod
        image: gcr.io/xxxx/uwsgi:latest <------ needs to be fully_qualified_digest
        name: uwsgi
        ports:
        - containerPort: 9040
        readinessProbe:
          httpGet:
            path: /health/
            port: 9040
          initialDelaySeconds: 5
          timeoutSeconds: 1
          periodSeconds: 15
        livenessProbe:
          httpGet:
            path: /health/
            port: 9040
          initialDelaySeconds: 60
          timeoutSeconds: 1
          periodSeconds: 15
        resources:
          requests:
            memory: "1000Mi"
            cpu: "1800m"
          limits:
            memory: "1200Mi"
            cpu: "2000m"
      hostname: uwsgi
      restartPolicy: Always
      terminationGracePeriodSeconds: 60
status: {}

【问题讨论】:

  • 是什么阻止你用 Python 编写一个小程序来检索完全限定的摘要并在使用之前更新 YAML 文件?
  • 我现在实际上正在这样做。

标签: kubernetes yaml google-kubernetes-engine digest


【解决方案1】:

有许多工具可以监视您的 Docker 存储库,并在新映像可用时进行更新。最常用的大概是https://github.com/weaveworks/flux/。 Kubernetes 本身不提供此功能,因为它可能无法收敛。

也就是说,您可以在 pod 规范中使用 :latest 就好了。避免它的原因是 Kubernetes 不会知道在图像更改时重新启动您的 pod(还有缓存问题,但您可以避免那些在规范中使用图像拉取策略的问题)。如果您实际上并不希望自动部署新映像,那么您所拥有的就可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 2012-10-20
    • 1970-01-01
    • 2019-12-14
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多