首页 > 解决方案 > kubernetes 没有从 docker 应用新的服务更新

问题描述

我有一个节点 JS 应用程序,我正在部署到 kubernetes。

我已经对节点 JS 应用程序进行了更改,并将该应用程序重新部署到 K8s。

但是,我注意到部署没有通过。

我检查了我的 docker hub,是的,正在部署最新的图像。这是我下面的 service.yaml 文件

apiVersion: v1
kind: Service
metadata:
  name: fourthapp
spec:
  type: LoadBalancer #Exposes the service as a node port
  ports:
  - port: 3000
    protocol: TCP
    targetPort: 3000
  selector:
    app: webapp

这是我的 deploy.yaml 文件

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: fourthapp
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        image: index.docker.io/leexha/nodejsapp:latest
        ports:
        - containerPort: 3000
        resources:
          requests: 
            memory: 500Mi
            cpu: 0.5
          limits:
            memory: 500Mi
            cpu: 0.5
        imagePullPolicy: Always

当我运行 service.yaml 它读取

C:\Users\adrlee\Desktop\oracle\Web_projects>kubectl apply -f service.yml
service "fourthapp" unchanged

有什么我做错了吗?

标签: dockerkubernetes

解决方案


If I understood the question you should update the Deployment instead. The service is just a kind of LB which dispatch traffic between your pods.

First, you should add imagePullPolicy: Always to the deployment to force k8s to download the newest image.

If you want to update the deployment you can run

kubectl apply -f deploy.yml

or performing a Rolling Update


推荐阅读