我有以下复制控制器在Kubernetes上的GKE:

apiVersion: v1
kind: ReplicationController
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  replicas: 2
  selector:
    app: myapp
    deployment: initial
  template:
    metadata:
      labels:
        app: myapp
        deployment: initial
    spec:
      containers:
      - name: myapp
        image: myregistry.com/myapp:5c3dda6b
        ports:
        - containerPort: 80
      imagePullPolicy: Always
      imagePullSecrets:
        - name: myregistry.com-registry-key

现在,如果我说

kubectl rolling-update myapp --image=us.gcr.io/project-107012/myapp:5c3dda6b

执行滚动更新,但不重新拉取。为什么?


当前回答

您可以在部署文件中定义imagePullPolicy: Always。

其他回答

您可以在部署文件中定义imagePullPolicy: Always。

我已经使用kubectl rollout restart我的springboot api和它的工作。

kubectl rollout restart -f pod-staging.yml --namespace test

部署的Yaml:

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
    name: "my-api"
    labels:
      app: "my-api"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: "my-api"
  template:
    metadata:
      labels:
        app: "my-api"
    spec:
      containers:
        - name: my-api
          image: harbor.url.com/mycompany/my-api:staging
          ports:
            - containerPort: 8099
              protocol: TCP
          imagePullPolicy: Always
          livenessProbe:
            httpGet:
              path: /actuator/health/liveness
              port: 8099
            initialDelaySeconds: 90
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /actuator/health/readiness
              port: 8099
            initialDelaySeconds: 90
            periodSeconds: 5
          envFrom:
            - configMapRef:
                name: "my-api-configmap"
          env:
            - name: "TOKEN_VALUE"
              valueFrom:
                secretKeyRef:
                  name: "my-api-secret"
                  key: "TOKEN_VALUE"
          resources:
            requests:
              memory: "512Mi"
              cpu: "500m"
            limits:
              memory: "2048Mi"
              cpu: "1000m"
      imagePullSecrets:
        - name: "my-ci-user"

如果你想在特定的pod上执行直接的图像更新,你也可以使用kubectl set image。

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

现在,命令kubectl rollout restart deploy your - deployment结合imagePullPolicy: Always策略将允许您使用最新版本的映像重新启动所有pod。

Image pull策略将总是在每次创建新pod时帮助拉出图像(这可以在任何情况下,如缩放副本,或pod死亡,并创建新pod)

但是如果你想要更新当前运行的pod的映像,部署是最好的方法。它让你完美无缺的更新没有任何问题(主要是当你有一个持久的卷附加到豆荚):)