helm3使用
一.helm架构

二.helm安装和常见命令
wget https://get.helm.sh/helm-v3.0.2-linux-amd64.tar.gz
tar zvxf helm-v3.0.2-linux-amd64.tar.gz
mv linux-amd64/helm /usr/bin/
#配置国内chart 仓库
helm repo add stable http://mirror.azure.cn/kubernetes/charts
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update
#查看配置的存储库
helm repo list
helm search repo stable
helm repo remove aliyun
#常用命令
helm search repo stable/mysql 查看mysql定义
helm list 查看安装应用
helm pull stable/mysql 拉取mysql
helm install mysql.tgz #本地存档安装
helm install path/to/foo #chart目录安装
helm install http://example.com/charts/msql.tgz #完整url
三.helm使用案例之安装mysql
helm install db stable/mysql #安装
helm status db #查看状态
helm show values stable/mysql > values.yaml 查看配置
#需要提前创建pv
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv33 #pv名称
spec:
capacity: #存储能力,一个pv对象都要指定一个存储能力,目前仅支持存储空间的设置
storage: 8Gi #存储空间
accessModes:
- ReadWriteOnce #访问模式
#persistentVolumeReclaimPolicy: Recycle #回收策略
nfs: #服务模式 (nfs、ceph、hostpath等)
path: /data/k8s-volume/db #共享数据目录挂载点
server: 10.206.16.4 #nfs服务器地址
~
###修改values.yaml
helm show values stable/mysql > values.yaml #到处values
helm install db2 -f values.yaml stable/mysql #应用values
#命令行替代方式
helm install db --set persistence.storageClass="managed-nfs-storage" stable/mysql
四.制作一个helm包
helm create nginx-demo #创建nginx helm
#删除template里面的内容
kubectl create deployment web --image=nginx --dry-run -o yaml > deployment.yaml
kubectl create deployment web --image=nginx
kubectl expose deployment web --port=80 --target-port=80 --dry-run -o yaml > service.yaml
kubectl delete deployment web --image=nginx
helm install web --dry-run /root/helm/nginx #调试是否正确
helm install web /root/helm/nginx #安装
#定义values参数形式传递给
#deployment.yaml定义
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
chart: {{ .Chart.Name }}
app: {{ .Release.Name }}
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Values.label }}
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: {{ .Values.label }}
spec:
containers:
- image: {{ .Values.image }}:{{ .Values.imageTag }}
name: {{ .Release.Name }}
resources: {}
status: {}
#service.yaml参数化
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
chart: {{ .Chart.Name}}
app: {{ .Release.Name }}
name: {{ .Release.Name}}
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: {{ .Values.label}}
status:
loadBalancer: {}
#values.yaml定义
replicas: 3
image: nginx
imageTag: 1.17
label: nginx
# 调试是否正确
helm install web --dry-run /root/nginx/
#安装
helm install web /root/nginx/
#升级
helm upgrade web /root/helm/nginx
kubectl get ep #查看endpoint
#单独设置某个参数的值
helm upgrade web --set replicas=2 /root/helm/nginx
极客飞兔 2 月前