安装helm客户端
在macOS上安装很简单:
brew install kubernetes-helm
其他平台请参考Installing Helm
配置RBAC
定义rbac-config.yaml文件,创建tiller账号,并和cluster-admin绑定:
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
执行命令:
代码语言:javascript复制$ kubectl create -f rbac-config.yaml
serviceaccount "tiller" created
clusterrolebinding "tiller" created
安装Tiller镜像
在强国环境内,需要参考kubernetes-for-china,将helm服务端部分Tiller的镜像下载到集群节点上。
初始化helm
执行初始化命令,注意指定上一步创建的ServiceAccount:
helm init --service-account tiller --history-max 200
命令执行成功,会在集群中安装helm的服务端部分Tiller。可以使用kubectl get pods -n kube-system命令查看:
$kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
...
tiller-deploy-7fbf5fc745-lxzxl 1/1 Running 0 179m
Quickstart
- 增加
Chart Repository(可选)
查看helm的Chart Repository:
$ helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
local http://127.0.0.1:8879/charts
如果你所处的网络环境无法访问缺省的Chart Repository,可以更换为其他repo,例如微软提供的 helm 仓库的镜像:
$ helm repo add stable http://mirror.azure.cn/kubernetes/charts/
"stable" has been added to your repositories
$ helm repo add incubator http://mirror.azure.cn/kubernetes/charts-incubator/
"incubator" has been added to your repositories
- 所有可用
chart列表:
helm repo update
helm search
- 搜索
tomcat chart:
helm search tomcat
- 查看
stable/tomcat的详细信息
helm inspect stable/tomcat
stable/tomcat使用 sidecar 方式部署web应用,通过参数image.webarchive.repository指定war的镜像,不指定会部署缺省的sample应用。
- 安装
tomcat:
如果是在私有化集群部署,设置service.type为NodePort:
helm install --name my-web --set service.type=NodePort stable/tomcat
- 测试安装效果
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services my-web-tomcat)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
# 访问sample应用
curl http://$NODE_IP:$NODE_PORT/sample/
- 列表和删除
helm list
helm del --purge my-web


