一、简介

1.1构建私有Chart仓库

使用Chart便于封装和管理kubernetes中的应用,因此当企业内部的应用多了以后,互相依赖、部署环境复杂之后,原先的直接使用yaml文件的管理方式已经不再适应生产的需要,因此我们有必要构建自己的chart仓库。本文中我们将通过阿里云效来构建我们自己的chart仓库。

1.2什么是Chart

Chart是helm管理的应用的打包格式。它包括如下特征:

  • Chart中包括一系列的yaml格式的描述文件。
  • 一个Chart只用来部署单个的应用的,不应该过于复杂,不应该包含多个依赖,相当于一个微服务。

Chart有特定的目录结构,可以打包起来进行版本控制。官方文档:https://helm.sh/docs/

1.3Chart的组成结构
[root@xiangys0134-k8s-node01 vone-front]# tree vone-front
vone-front
├── charts
├── Chart.yaml
├── templates
│   ├── configmap.yaml
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── service.yaml
│   ├── tests
│   │   └── test-connection.yaml
│   └── tls-secrets.yaml
└── values.yaml
#备注:helm采用go模板语法,针对不同环境配置values.yaml即可
1.4持续集成介绍

通过pipline构建镜像和更新chart包。架构如下所示

image-20201015143414590

1.5helm安装服务

在线安装步骤:

  • 查看helm最新版本
  • 在线install安装
  • 检查Pod状态是否允许正常

离线安装步骤:

  • 在有网络环境下fetch对应helm版本至本地
  • 修改docker镜像tag(例如当前更新的tag为1.2.4)
  • 将镜像push至内网私有仓库
  • helm install安装
  • 检查Pod状态是否允许正常
1.6helm升级服务

在线升级步骤:

  • 指定当前需要升级的镜像tag
  • helm upgrade命令升级

离线升级步骤:

  • 在有网络环境下fetch对应helm版本至本地
  • 指定当前需要升级的镜像tag
  • 将镜像版本push至内网私有仓库
  • helm upgrade命令升级
1.7helm安装升级架构图

image-20201015144750298

二、helm在线安装版本

2.1更新helm repo
[root@xiangys0134-k8s-node01 vone-front]# helm repo update
2.2搜索对应helm版本
[root@xiangys0134-k8s-node01 vone-front]# helm search repo vone-front
NAME                        CHART VERSION   APP VERSION DESCRIPTION                
133887-xc_ops/vone-front    0.1.3           0.1.1       A Helm chart for Kubernetes

备注:仓库133887-xc_ops为helm私有仓库
2.3指定本地环境配置文件
[root@xiangys0134-k8s-node01 vone-front]# vi test-values.yaml
image:
  repository: registry.cn-hangzhou.aliyuncs.com/xunceprivate/vone
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: vone-front-v1.2.3B_202010141450

hostname: vone-front.xuncetech.com

configmap:
  nginx:
    PROXY_COMMON_HOST: www.xuncetech.com
    PROXY_COMMON_PORT: 8762
    PROXY_DATA_SERVICE_HOST: www.xuncetech.com
    PROXY_ANALYSIS_HOST: www.xuncetech.com
    PROXY_ANALYSIS_PORT: 8762
    PROXY_RISK_HOST: www.xuncetech.com
    PROXY_RISK_PORT: 8762
    PROXY_API_SERVICE_HOST: www.xuncetech.com
    PROXY_API_SERVICE_PORT: 8701
    PROXY_API_XONE_HOST: 192.168.0.151
    PROXY_API_XONE_PORT: 9762
2.4安装helm版本
[root@xiangys0134-k8s-node01 vone-front]# kubectl create ns xc-ops          #创建k8s集群名称空间
[root@xiangys0134-k8s-node01 vone-front]# helm install vone-front --namespace xc-ops -f test-values.yaml --version 0.1.3 133887-xc_ops/vone-front

备注:指定helm版本--version 加载指定配置文件 -f
2.5 查看helm release
[root@xiangys0134-k8s-node01 vone-front]# helm list -n xc-ops
NAME        NAMESPACE   REVISION    UPDATED                                 STATUS      CHART               APP VERSION
vone-front  xc-ops      1           2020-10-15 14:58:16.537763014 +0800 CST deployed    vone-front-0.1.3    0.1.1
2.6kube查看状态
[root@xiangys0134-k8s-node01 vone-front]# kubectl get pods -n xc-ops
NAME                         READY   STATUS    RESTARTS   AGE
vone-front-f8f798fc6-wsn4q   1/1     Running   0          2m3s

备注:kubectl可以查看pod状态,同时也可以使用dashboard等其他方式查看
2.7检查服务运行状态

k8s集群采用ingress-nginx作为七层访问代理入口。访问时需要配置域名访问

[root@xiangys0134-k8s-node02 tmp]# curl -I -x 192.168.10.116:80 -s http://vone-front.xuncetech.com/index.html
HTTP/1.1 200 OK
Server: nginx/1.17.8
Date: Thu, 15 Oct 2020 08:04:16 GMT
Content-Type: text/html
Content-Length: 654
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Thu, 15 Oct 2020 06:13:40 GMT
ETag: "5f87e894-28e"
Cache-Control: no-store
Accept-Ranges: bytes

三、helm在线升级

3.1更新helm repo
[root@xiangys0134-k8s-node01 vone-front]# helm repo update
[root@xiangys0134-k8s-node01 vone-front]# helm search repo vone-front
NAME                        CHART VERSION   APP VERSION DESCRIPTION                
133887-xc_ops/vone-front    0.1.4           0.1.1       A Helm chart for Kubernetes
3.2升级helm版本
[root@xiangys0134-k8s-node01 vone-front]# helm upgrade vone-front -f test-values.yaml --namespace xc-ops --version 0.1.4 133887-xc_ops/vone-front

四、helm离线安装版本

4.1fetch获取版本包
[root@xiangys0134-k8s-node01 tmp]# helm fetch --version 0.1.4 133887-xc_ops/vone-front
备注:在有helm操作权限的主机操作,并将版本包拷贝至对应的更新服务器上
4.2安装helm版本
[root@xiangys0134-k8s-node01 tmp]# tar -zxvf vone-front-0.1.4.tgz
[root@xiangys0134-k8s-node01 tmp]# helm install vone-front --namespace xc-ops -f test-values.yaml vone-front

#备注:指定对应helm版本的目录

五、helm在线升级

最后修改日期: 2020年10月15日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。