持续集成交付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)解决方法

修改配置文件。

修改前:

修改后:

成功:

相关推荐
Pythonliu72 小时前
茴香豆 + Qwen-7B-Chat-Int8
linux·运维·服务器
你疯了抱抱我2 小时前
【RockyLinux 9.4】安装 NVIDIA 驱动,改变分辨率,避坑版本。(CentOS 系列也能用)
linux·运维·centos
小O_好好学4 小时前
CentOS 7文件系统
linux·运维·centos
哲伦贼稳妥4 小时前
一天认识一个硬件之机房地板
运维·网络·经验分享·其他
john_hjy5 小时前
11. 异步编程
运维·服务器·javascript
x晕x5 小时前
Linux dlsym符号查找疑惑分析
linux·运维·服务器
活跃的煤矿打工人5 小时前
【星海saul随笔】Ubuntu基础知识
linux·运维·ubuntu
tangdou3690986556 小时前
两种方案手把手教你多种服务器使用tinyproxy搭建http代理
运维·后端·自动化运维
北京智和信通6 小时前
云平台和虚拟化智慧运维监控,全面提升故障感知与处置能力
运维·虚拟化·云平台·虚拟机监控
fasewer6 小时前
第五章 linux实战-挖矿 二
linux·运维·服务器