helm安装(v3版本)
下载安装包
解压安装包,并移动到/usr/bin/目录下
tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
cd linux-amd64/
ls
mv helm /usr/bin/
移动后即可使用
配置helm仓库
(1)添加仓库
helm repo add 仓库名 仓库地址
添加微软仓库
helm repo add stable http://mirror.azure.cn/kubernetes/charts
查看仓库
helm repo list
添加阿里云仓库
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
查看仓库
helm repo list
更新仓库
helm repo update
删除仓库
helm repo remove aliyun
使用helm快速部署应用
1.使用命令搜索应用
helm search repo 名称(weave)
2.根据搜索内容选择安装
helm install 安装之后的名称 搜索之后的应用名称
#例子
helm install ui stable/weave-scope
3.查看发布状态
helm list
helm status 安装之后的名称
查看
修改service的yaml文件,type改为:NodePort
kubectl edit svc ui-weave-scope
创建Chart
1.使用命令创建chart
helm create mychart
- Chart.yaml:当前chart属性配置信息
- templates:编写yaml文件放到这个目录中
- values.yaml:yaml文件可以使用全局变量
2.在templates文件夹创建两个yaml文件
- deployment.yaml
- service.yaml
#创建deployment文件,不新建deployment
kubectl create deployment web1 --image=nginx --dry-run -o yaml > deployment.yaml
#创建deployment
kubectl create deployment web1 --image=nginx
vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web1
name: web1
spec:
replicas: 1
selector:
matchLabels:
app: web1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web1
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
#创建service.yaml文件,不新建service
kubectl expose deployment web1 --port=80 --target-port=80 --type=NodePort --dry-run -o yaml > service.yaml
vim service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: web1
name: web1
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: web1
type: NodePort
status:
loadBalancer: {}
3.安装mychart
#安装mychart
helm install web1 mychart
#删除创建的mychart phoenix-chart 为name ;other 为namespace
helm uninstall phoenix-chart --namespace other
kubectl get pods
kubectl get svc
4.应用升级
helm upgrade web1 mychart/
实现yaml高效服用
在value.yaml定义变量和值
cd mychart/
vim value.yaml
在templates的yaml文件使用value.yaml定义变量
通过表达式形式使用全局变量
{{.Values.变量名称}}
vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: {{.Values.label}}
name: {{.Release.Name}}-deploy
spec:
replicas: {{.Values.replicas}}
selector:
matchLabels:
app: {{.Values.label}}
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: {{.Values.label}}
spec:
containers:
- image: {{.Values.image}}
name: nginx
resources: {}
status: {}
vim service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: {{.Values.label}}
name: {{.Values.label}}-svc
spec:
ports:
- port: {{.Values.port}}
protocol: TCP
targetPort: 80
selector:
app: {{.Values.label}}
type: NodePort
status:
loadBalancer: {}
helm install --dry-run web2 mychart/
创建
helm install web2 mychart/