Helm是一个Kubernetes的包管理工具,就像Linux下的包管理工具,可以很方便的将之前打包好的yaml文件部署到Kubernetes上.
官网地址:https://helm.sh/zh/
wget https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz
tar -zxf helm-v3.5.2-linux-amd64.tar.gz
mv linux-amd64/helm /usr/bin/
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo list # 查看helm仓库地址
helm repo update # 更新仓库地址
helm repo remove aliyun # 移除aliyun仓库
helm search repo weave # 搜索一个weave应用
helm install docker-ui aliyun/weave-scope # 安装一个应用
helm list # 查看安装列表
helm status docker-ui # 查看状态
由于服务没有对外暴露端口,所以需要修改Yaml文件
kubectl edit svc weave-scope-weave-scope
type: NodePort # type改为NodePort
http://172.16.87.10:31556/ # 访问NodePort端口即可
使用chart部署一个应用
helm create chart # 先创建一个chart模板
├── chart
├── Chart.yaml # 当前chart的属性配置信息
├── templates # 存放模板的目录
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml # 定义全局变量的文件
cd templates/ # 进入到模板目录
kubectl create deployment web-server --image=nginx:1.7.9 --dry-run -o yaml > deployment.yaml
kubectl expose deployment web-server --port=80 --target-port=80 --type=NodePort --dry-run -o yaml > service.yaml
helm install web-server chart/ # 使用helm直接创建应用
helm upgrade web-server chart/
Release "web-server" has been upgraded. Happy Helming!
NAME: web-server
LAST DEPLOYED: Sun Feb 28 17:40:39 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
image
tag
label
port
replicas
vim value.yaml
# base Infomation
replicas: 1
image: nginx
tag: 1.7.9
label: nginx
port: 80
# {{.Values.Name}}
# {{.Release.Name}} 取一个动态生成的名字.
vim templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: {{ .Values.label }} # 改动处
name: {{ .Release.Name }}-deployment # 改动处
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.label }} # 改动处
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: {{ .Values.label }} # 改动处
spec:
containers:
- image: {{ .Values.image }} # 改动处
resources: {}
status: {}
vim templates/service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: {{ .Values.label }} # 改动处
name: {{ .Release.Name }}-svc # 修改处
spec:
ports:
- port: {{ .Values.port }} # 修改处
protocol: TCP
targetPort: 80
selector:
app: {{ .Values.label }} # 修改处
type: NodePort
status:
loadBalancer: {}
helm install --dry-run web2 charts/ # 起的名字叫web2
--dry-run
:表示尝试运行helm install web2 charts/ # 实际运行