K8s滚动更新无法在负载均衡器中正常切换容器

时间:2017-04-22 21:58:21

标签: kubernetes google-kubernetes-engine

更改Web部署的映像版本并在具有1个副本的部署中触发滚动更新时,将创建并运行具有新版本的其他窗格。但是,在负载均衡器似乎切换到新容器之前,仍然会终止活动容器。

正在运行curl http://<Load Balancer Ingress IP>/mynode.test?[1-2000]会在切换过程中显示错误。

我尝试了一些可能会破坏时机的事情。

这些是我的yaml文件和gcloud命令:

gcloud container \
clusters create "sling-cluster-small" \
--project "devops-test" \
--zone "us-central1-a" \
--machine-type "g1-small" \
--num-nodes "3" \
--network "default"

gcloud compute disks create \
  --project "devops-test" \
  --zone "us-central1-a" \
  --size 200GB \
  mongo-disk

DB-deployment.yml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mongo-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: mongo
    spec:
      containers:
      - image: mongo
        name: mongo
        ports:
        - name: mongo
          containerPort: 27017
          hostPort: 27017
        volumeMounts:
          - name: mongo-persistent-storage
            mountPath: /data/db
      volumes:
        - name: mongo-persistent-storage
          gcePersistentDisk:
            pdName: mongo-disk
            fsType: ext4

DB-service.yml:

apiVersion: v1
kind: Service
metadata:
 labels:
   name: mongo
 name: mongo
spec:
 ports:
   - port: 27017
     targetPort: 27017
 selector:
   name: mongo

网络deployment.yml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web-deployment
spec:
  replicas: 1
#  minReadySeconds: 60
  strategy:
    rollingUpdate:
      maxUnavailable: 0
  template:
    metadata:
      labels:
        name: web
    spec:
      containers:
# 0.1.2 and 0.2.2 are the two valid versions
      - image: sandroboehme/sample-app:0.1.2
#      - image: sandroboehme/sample-app:0.2.2
        name: web
        ports:
        - name: http-server
          containerPort: 8080
        readinessProbe:
          httpGet:
            path: /mynode.test
            port: 8080
          initialDelaySeconds: 90
          timeoutSeconds: 30
          periodSeconds: 5
        lifecycle:
          preStop:
            exec:
              # A workaround to get 0% downtime during deploys. This should
              command: ["sh", "-c", "curl http://localhost:8080/mynode.test?ready=false -u admin:admin && sleep 15"]

网络service.yml:

apiVersion: v1
kind: Service
metadata:
 name: web
 labels:
   name: web
spec:
# type: NodePort
 type: LoadBalancer
 ports:
   - port: 80
     targetPort: 8080
     protocol: TCP
#     nodePort: 30000
 selector:
   name: web

怎么能处理呢? 任何帮助深表感谢!感谢您抽出时间调查此事!

0 个答案:

没有答案