我有以下复制控制器在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

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


当前回答

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

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

其他回答

指定策略为:

  strategy: 
    type: Recreate
    rollingUpdate: null

确保每个部署都有不同的注释。Helm是这样做的:

  template:
    metadata:
      labels:
        app.kubernetes.io/name: AppName
        app.kubernetes.io/instance: ReleaseName
      annotations:
        rollme: {{ randAlphaNum 5 | quote }}

指定图像提取策略- Always

      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          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/

要么你已经手动删除了所有的豆荚,以再次拉出图像来重新创建。

or

运行下面的命令 Kubectl rollout重启deploy /deployment_name Kubectl rollout重启部署/nginx

这个命令应该重新创建所有的pod。

对于这两种情况,imagepullPolicy应该设置为Always。