持续集成交付CICD:HELM 手动完成前端项目应用发布与回滚

目录

一、实验

1.环境

[2.K8S master节点部署HELM3](#2.K8S master节点部署HELM3)

[3.K8S master节点安装git](#3.K8S master节点安装git)

[4. Harbor镜像确认](#4. Harbor镜像确认)

[5. HELM 手动完成前端项目应用发布与回滚](#5. HELM 手动完成前端项目应用发布与回滚)

6.代码上传到GitLab

二、问题

[1.Ingress中 path 的类型有何区别](#1.Ingress中 path 的类型有何区别)

[2. HELM创建项目报错](#2. HELM创建项目报错)


一、实验

1.环境

(1)主机

表1 主机

|---------|--------------|----------|---------------------|---------------------|
| 主机 | 架构 | 版本 | IP | 备注 |
| master1 | K8S master节点 | 1.20.6 | 192.168.204.180 | jenkins slave (从节点) |
| | helm | 3.6.0 | | |
| | git | 1.8.3.1 | | |
| node1 | K8S node节点 | 1.20.6 | 192.168.204.181 | |
| node2 | K8S node节点 | 1.20.6 | 192.168.204.182 | |
| jenkins | jenkins主节点 | 2.414.2 | 192.168.204.15:8080 | gitlab runner (从节点) |
| | harbor私有仓库 | 1.2.2 | 192.168.204.15 | |
| gitlab | gitlab 主节点 | 12.10.14 | 192.168.204.8:82 | jenkins slave (从节点) |
| | sonarqube | 9.6 | 192.168.204.8:9000 | |

2.K8S master节点部署HELM3

(1)Helm版本与K8S集群兼容

(2)查看K8S集群状态

bash 复制代码
# kubectl get node

(3)策略

当前K8S 集群为1.20.6版本,HELM 3.6.x 版本可以兼容。

所以选择3.6.0版本。

(4)部署

bash 复制代码
1)安装 helm 
//下载二进制 Helm client 安装包
helm-v3.6.0-linux-amd64.tar.gz
 
tar -zxvf helm-v3.6.0-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
helm version
 
//命令补全
source <(helm completion bash)
 
2)使用 helm 安装 Chart
//添加常用的 chart 仓库,
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add incubator https://charts.helm.sh/incubator

3) 更新 charts 列表
helm repo update
helm repo list          

安装

使用 helm 安装 Chart

3.K8S master节点安装git

(1) 安装

bash 复制代码
1)安装
# yum install -y git

2)查看版本
# git --version

3)全局设置(初始邮箱为admin@example.com)
# git config --global user.name "root"
# git config --global user.email "594372682@qq.com"

安装

查看版本

全局设置

4. Harbor镜像确认

(1)查看前端项目镜像

(2)确认如下镜像作为helm项目使用的镜像

bash 复制代码
 192.168.204.15/devops03/devops03-devops-ui:RELEASE-1.1.6

5. HELM 手动完成前端项目应用发布与回滚

(1)构建项目

bash 复制代码
# helm create devops03-devops-ui

(2)安装tree

bash 复制代码
# yum install -y tree

(3) 查看目录

bash 复制代码
# tree

(4)修改values.yaml

bash 复制代码
# vim values.yaml 

指定镜像仓库、镜像版本为RELEASE-1.1.6、开启ingress

bash 复制代码
  1 # Default values for devops03-devops-ui.
  2 # This is a YAML-formatted file.
  3 # Declare variables to be passed into your templates.
  4 
  5 replicaCount: 2
  6 
  7 image:
  8   repository: 192.168.204.15/devops03/devops03-devops-ui
  9   pullPolicy: IfNotPresent
 10   # Overrides the image tag whose default is the chart appVersion.
 11   tag: "RELEASE-1.1.6"
 12 
 13 imagePullSecrets: []
 14 nameOverride: ""
 15 fullnameOverride: ""
 16 
 17 serviceAccount:
 18   # Specifies whether a service account should be created
 19   create: true
 20   # Annotations to add to the service account
 21   annotations: {}
 22   # The name of the service account to use.
 23   # If not set and create is true, a name is generated using the fullname template
 24   name: ""
 25 
 26 podAnnotations: {}
 27 
 28 podSecurityContext: {}
 29   # fsGroup: 2000
 30 
 31 securityContext: {}
 32   # capabilities:
 33   #   drop:
 34   #   - ALL
 35   # readOnlyRootFilesystem: true
 36   # runAsNonRoot: true
 37   # runAsUser: 1000
 38 
 39 service:
 40   type: ClusterIP
 41   port: 80
 42 
 43 ingress:
 44   enabled: true
 45   className: ""
 46   annotations:
 47     kubernetes.io/ingress.class: nginx
 48     # kubernetes.io/tls-acme: "true"
 49   hosts:
 50     - host: devops03-devops-ui.devops.com
 51       paths:
 52         - path: /
 53           pathType: ImplementationSpecific
 54   tls: []
 55   #  - secretName: chart-example-tls
 56   #    hosts:
 57   #      - chart-example.local
 58 
 59 resources: {}
 60   # We usually recommend not to specify default resources and to leave this as a conscious
 61   # choice for the user. This also increases chances charts run on environments with little
 62   # resources, such as Minikube. If you do want to specify resources, uncomment the following
 63   # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
 64   # limits:
 65   #   cpu: 100m
 66   #   memory: 128Mi
 67   # requests:
 68   #   cpu: 100m
 69   #   memory: 128Mi
 70 
 71 autoscaling:
 72   enabled: false
 73   minReplicas: 1
 74   maxReplicas: 100
 75   targetCPUUtilizationPercentage: 80
 76   # targetMemoryUtilizationPercentage: 80
 77 
 78 nodeSelector: {}
 79 
 80 tolerations: []
 81 
 82 affinity: {}

(5) 另开一个终端用watch命令观察pod变化

# watch -n 1 "kubectl get pod -n devops03"

(6)外部测试访问(当前版本为1.1.6)

# curl http://devops03-devops-ui.devops.com:31291

(7)删除已有命名空间

bash 复制代码
# kubectl delete ns devops03

(8)观察pod变化

(9)重新创建命名空间并查看资源

bash 复制代码
# kubectl create ns devops03

# kubectl get all -n devops03

(7)运行项目

bash 复制代码
# helm install devops03-devops-ui -n devops03 devops03-devops-ui/

(8)观察pod变化

(9)外部测试访问(当前版本为1.1.6)

# curl http://devops03-devops-ui.devops.com:31291

(10)修改values.yaml

bash 复制代码
# vim values.yaml 

指定镜像仓库、镜像版本为RELEASE-1.1.5、开启ingress

bash 复制代码
  1 # Default values for devops03-devops-ui.
  2 # This is a YAML-formatted file.
  3 # Declare variables to be passed into your templates.
  4 
  5 replicaCount: 2
  6 
  7 image:
  8   repository: 192.168.204.15/devops03/devops03-devops-ui
  9   pullPolicy: IfNotPresent
 10   # Overrides the image tag whose default is the chart appVersion.
 11   tag: "RELEASE-1.1.6"
 12 
 13 imagePullSecrets: []
 14 nameOverride: ""
 15 fullnameOverride: ""
 16 
 17 serviceAccount:
 18   # Specifies whether a service account should be created
 19   create: true
 20   # Annotations to add to the service account
 21   annotations: {}
 22   # The name of the service account to use.
 23   # If not set and create is true, a name is generated using the fullname template
 24   name: ""
 25 
 26 podAnnotations: {}
 27 
 28 podSecurityContext: {}
 29   # fsGroup: 2000
 30 
 31 securityContext: {}
 32   # capabilities:
 33   #   drop:
 34   #   - ALL
 35   # readOnlyRootFilesystem: true
 36   # runAsNonRoot: true
 37   # runAsUser: 1000
 38 
 39 service:
 40   type: ClusterIP
 41   port: 80
 42 
 43 ingress:
 44   enabled: true
 45   className: ""
 46   annotations:
 47     kubernetes.io/ingress.class: nginx
 48     # kubernetes.io/tls-acme: "true"
 49   hosts:
 50     - host: devops03-devops-ui.devops.com
 51       paths:
 52         - path: /
 53           pathType: ImplementationSpecific
 54   tls: []
 55   #  - secretName: chart-example-tls
 56   #    hosts:
 57   #      - chart-example.local
 58 
 59 resources: {}
 60   # We usually recommend not to specify default resources and to leave this as a conscious
 61   # choice for the user. This also increases chances charts run on environments with little
 62   # resources, such as Minikube. If you do want to specify resources, uncomment the following
 63   # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
 64   # limits:
 65   #   cpu: 100m
 66   #   memory: 128Mi
 67   # requests:
 68   #   cpu: 100m
 69   #   memory: 128Mi
 70 
 71 autoscaling:
 72   enabled: false
 73   minReplicas: 1
 74   maxReplicas: 100
 75   targetCPUUtilizationPercentage: 80
 76   # targetMemoryUtilizationPercentage: 80
 77 
 78 nodeSelector: {}
 79 
 80 tolerations: []
 81 
 82 affinity: {}

修改前:

修改后:

(11)更新项目

bash 复制代码
# helm upgrade devops03-devops-ui -n devops03 devops03-devops-ui/

(12)观察pod变化

(13)外部测试访问(当前版本为1.1.5)

# curl http://devops03-devops-ui.devops.com:31291

(14)查看历史版本

bash 复制代码
# helm history devops03-devops-ui -n devops03

(15)回滚指定版本

bash 复制代码
# helm rollback devops03-devops-ui 1 -n devops03

(16)观察pod变化

(17)外部测试访问(当前版本为1.1.6)

# curl http://devops03-devops-ui.devops.com:31291

6.代码上传到GitLab

(1) 将项目克隆到服务器

bash 复制代码
# git clone http://192.168.204.8:82/devops03/devops03-helm-service.git

(2)切换目录,移动HELM项目

bash 复制代码
# mv devops03-devops-ui/ devops03-helm-service/

(3)将代码上传到工作区

bash 复制代码
# git add devops03-devops-ui/

(4)提交代码申明

bash 复制代码
# git commit -m "devops03 app"

(5) 将代码推送到GitLab

bash 复制代码
# git push origin master

(6)GitLab查看项目

(7)目录结构

二、问题

1.Ingress中 path 的类型有何区别

(1)区别

bash 复制代码
exact: 精确匹配路径。如 path: /foo,只匹配请求路径与之完全相同的 /foo。

prefix: 前缀匹配路径。如 path: /foo,匹配请求路径以 /foo 开始的所有路径,如 /foo、/foo/bar 等。

ImplementationSpecific: 特定 Ingress controller 的匹配方式。如 Nginx Ingress controller 忽略路径类型,作为前缀匹配路径处理。

2. HELM创建项目报错

(1)报错

(2)原因分析

格式转换错误。

(3)解决方法

修改配置文件。

修改前:

修改后:

成功:

相关推荐
...:...:...7 分钟前
Linux 第三次脚本作业
linux·运维·服务器
web2u1 小时前
Docker入门及基本概念
java·运维·服务器·spring·docker·容器
元气满满的热码式2 小时前
Docker实战-使用docker compose搭建博客
运维·docker·容器
不良人天码星3 小时前
Linux的基础指令和环境部署,项目部署实战(下)
linux·运维·服务器
EasyNVR4 小时前
基于WebRTC与AI大模型接入EasyRTC:打造轻量级、高实时、强互动的嵌入式音视频解决方案
运维·服务器·微信·小程序·webrtc·p2p·智能硬件
技术小齐5 小时前
网络运维学习笔记 022 HCIA-Datacom新增知识点03园区网典型组网架构及案例实战
运维·网络·学习
Java潘老师5 小时前
Automa 浏览器自动化编排 实现自动化浏览器操作
运维·自动化
waves浪游5 小时前
Linux基本指令(上)
linux·运维·服务器
是北欢吆6 小时前
QQ登录测试用例报告
运维·服务器·测试用例
9毫米的幻想7 小时前
【Linux系统】—— 冯诺依曼体系结构与操作系统初理解
linux·运维·服务器·c语言·c++