【Kubernetes系列】K8s更新镜像的几种方法


一、准备

以下以前端的服务为例,前端 yaml 文件内容如下:

vi deploy-ui.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: shop-ui

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: manager-ui
  namespace: shop-ui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: manager-ui
  template:
    metadata:
      labels:
        app: manager-ui
    spec:
      containers:
      - name: manager-ui
        image: 192.168.1.48/shop-ui/manager-ui:4.2.3.7
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: manager-ui-service
  namespace: shop-ui
spec:
  selector:
    app: manager-ui
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 10003
  type: NodePort

二、更新镜像

1.方法一:修改 yaml 文件版本号并执行

image: 192.168.1.48/shop-ui/manager-ui:4.2.3.7

改为:

image: 192.168.1.48/shop-ui/manager-ui:4.2.3.8

执行:

kubectl apply -f deploy-ui.yaml

2.方法二:使用 set image

set image deploy manager-ui -n shop-ui *=192.168.1.48/shop-ui/manager-ui:4.2.3.8

3.方法三:使用 patch

patch deployment manager-ui -n shop-ui --patch \'{
    
    "spec": {
    
    "template": {
    
    "spec": {
    
    "containers": [{
    
    "name": "manager-ui","image":"192.168.1.48/shop-ui/manager-ui:4.2.3.1"}]}}}}\'

猜你喜欢

转载自blog.csdn.net/u012069313/article/details/125365945
今日推荐