Tiller - 服务端 运行在 Kubernetes 中, 处理 Helm Client 的请求, 通过 REST、JSON 与 kubernetes API Server 进行交互.
客户端部署
安装依赖
1
2
3
4
# 首先要在所有 node 里安装 socat 软件
yum -y install socat
下载 helm 二进制文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
wget https://get.helm.sh/helm-v2.16.10-linux-amd64.tar.gz
tar zxvf helm-v2.16.10-linux-amd64.tar.gz
cd linux-amd64/
mv helm /usr/local/bin/
# 验证服务[root@kubernetes ~]# helm version
Client: &version.Version{SemVer:"v2.16.10", GitCommit:"bceca24a91639f045f22ab0f41e47589a932cf5e", GitTreeState:"clean"}
Error: could not find tiller
root@kubernetes:/opt/helm# helm init --skip-refresh
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://v2.helm.sh/docs/securing_installation/
Happy Helming!
# helm 的 repo 默认是使用 谷歌的 repo ,国内访问不到,修改为 阿里云 的 repo
[root@kubernetes ~]# helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
local http://127.0.0.1:8879/charts
[root@kubernetes ~]# helm repo remove stable
"stable" has been removed from your repositories
[root@kubernetes ~]# helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"stable" has been added to your repositories
[root@kubernetes ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
[root@kubernetes ~]# helm repo list
NAME URL
local http://127.0.0.1:8879/charts
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
Helm v2 自定义模板
自定义 Helm 模板 需要包含 Chart.yaml 文件、templates 模板目录.
Chart.yaml 文件是描述文件, 用于描述该应用的信息. 必须包含 name 与 version .
root@kubernetes:/opt/helm/nginx# helm install -n my-nginx .
NAME: my-nginx
LAST DEPLOYED: Tue Aug 18 09:55:12 2020
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-dm 0/2 201s==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
nginx-dm-5f7cb96cd8-qjttm 0/1 ContainerCreating 0 1s
nginx-dm-5f7cb96cd8-rdrsh 0/1 ContainerCreating 01s==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-svc ClusterIP 10.254.143.201 <none> 80/TCP 1s
查看服务
1
2
3
4
5
6
7
root@kubernetes:/opt/helm/nginx# helm ls
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
my-nginx 1 Tue Aug 18 09:55:12 2020 DEPLOYED my-nginx-1.0.0 default
1
2
3
4
5
6
7
8
9
10
root@kubernetes:/opt/helm/nginx# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-dm-5f7cb96cd8-qjttm 1/1 Running 0 2m2s
pod/nginx-dm-5f7cb96cd8-rdrsh 1/1 Running 0 2m2s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 92m
service/nginx-svc ClusterIP 10.254.143.201 <none> 80/TCP 2m2s
root@kubernetes:/opt/helm/nginx# helm upgrade my-nginx .
Release "my-nginx" has been upgraded.
LAST DEPLOYED: Tue Aug 18 10:05:13 2020
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-dm 2/2 1210m==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
nginx-dm-55c68cdfc9-7fmh2 0/1 ContainerCreating 0 0s
nginx-dm-5f7cb96cd8-qjttm 1/1 Running 0 10m
nginx-dm-5f7cb96cd8-rdrsh 1/1 Running 010m==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-svc ClusterIP 10.254.143.201 <none> 80/TCP 10m
1
2
3
4
root@kubernetes:/opt/helm/nginx# helm ls
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
my-nginx 2 Tue Aug 18 10:05:13 2020 DEPLOYED my-nginx-1.0.0 default
查看操作历史
查看应用操作历史 history
helm history my-nginx
1
2
3
4
5
root@kubernetes:/opt/helm/nginx# helm history my-nginx
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Aug 18 09:55:12 2020 SUPERSEDED my-nginx-1.0.0 Install complete2 Tue Aug 18 10:05:13 2020 DEPLOYED my-nginx-1.0.0 Upgrade complete
回滚应用
将应用回滚到之前的版本 rollback
helm rollback my-nginx 1
1 为 REVISION 号, 使用 helm history xx 可查看应用的更新信息
1
2
3
4
root@kubernetes:/opt/helm/nginx# helm rollback my-nginx 1
Rollback was a success.
查看信息
1
2
3
4
5
6
7
root@kubernetes:/opt/helm/nginx# helm history my-nginx
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Aug 18 09:55:12 2020 SUPERSEDED my-nginx-1.0.0 Install complete2 Tue Aug 18 10:05:13 2020 SUPERSEDED my-nginx-1.0.0 Upgrade complete3 Tue Aug 18 10:18:37 2020 DEPLOYED my-nginx-1.0.0 Rollback to 1
root@kubernetes:/opt/helm/myapp# helm upgrade myapp .
Release "myapp" has been upgraded.
LAST DEPLOYED: Wed Aug 19 03:30:24 2020
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
myapp 2/2 1210m==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
myapp-554ff5979c-5k8w5 0/1 ContainerCreating 0 0s
myapp-846dbc5c6-2c58f 1/1 Running 0 10m
myapp-846dbc5c6-qb7jv 1/1 Running 010m==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
myapp-svc ClusterIP 10.254.90.247 <none> 80/TCP 10m
测试访问
1
2
3
4
5
6
root@kubernetes:/opt/helm/myapp# helm history myapp
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Wed Aug 19 03:20:04 2020 SUPERSEDED myapp-v1 Install complete2 Wed Aug 19 03:30:24 2020 DEPLOYED myapp-v1 Upgrade complete