持续集成交付CICD:HELM 手动完成前端项目应用发布与回滚
2023-12-21 06:17:11
目录
?
?
一、实验
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集群状态
# kubectl get node
(3)策略
当前K8S 集群为1.20.6版本,HELM 3.6.x 版本可以兼容。
所以选择3.6.0版本。
(4)部署
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) 安装
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项目使用的镜像
192.168.204.15/devops03/devops03-devops-ui:RELEASE-1.1.6
?
5. HELM 手动完成前端项目应用发布与回滚
(1)构建项目
# helm create devops03-devops-ui
(2)安装tree
# yum install -y tree
(3) 查看目录
# tree
(4)修改values.yaml?
# vim values.yaml
指定镜像仓库、镜像版本为RELEASE-1.1.6、开启ingress
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)删除已有命名空间
# kubectl delete ns devops03
(8)观察pod变化
(9)重新创建命名空间并查看资源
# kubectl create ns devops03
# kubectl get all -n devops03
(7)运行项目
# 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?
# vim values.yaml
指定镜像仓库、镜像版本为RELEASE-1.1.5、开启ingress
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)更新项目
# 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)查看历史版本
# helm history devops03-devops-ui -n devops03
(15)回滚指定版本
# 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)?将项目克隆到服务器
# git clone http://192.168.204.8:82/devops03/devops03-helm-service.git
(2)切换目录,移动HELM项目
# mv devops03-devops-ui/ devops03-helm-service/
(3)将代码上传到工作区
# git add devops03-devops-ui/
(4)提交代码申明
# git commit -m "devops03 app"
(5)?将代码推送到GitLab
# git push origin master
(6)GitLab查看项目
(7)目录结构
?
二、问题
1.Ingress中 path 的类型有何区别
(1)区别
exact: 精确匹配路径。如 path: /foo,只匹配请求路径与之完全相同的 /foo。
prefix: 前缀匹配路径。如 path: /foo,匹配请求路径以 /foo 开始的所有路径,如 /foo、/foo/bar 等。
ImplementationSpecific: 特定 Ingress controller 的匹配方式。如 Nginx Ingress controller 忽略路径类型,作为前缀匹配路径处理。
2. HELM创建项目报错
(1)报错
(2)原因分析
格式转换错误。
(3)解决方法
修改配置文件。
修改前:
修改后:
成功:
?
?
文章来源:https://blog.csdn.net/cronaldo91/article/details/135098756
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!