[root@master1 helm]# helm create xianchao
[root@master1 helm]# tree xianchao
xianchao
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
3 directories, 8 files
[root@master1 xianchao]# cat Chart.yaml
apiVersion: v1//api版本,跟部署k8s应用无关系
appVersion: "1.0"//app版本,跟部署k8s应用无关系
description: A Helm chart for Kubernetes //描述
name: xianchao//Chart的名称,跟部署k8s应用无关系
version: 0.1.0//Chart的版本,跟部署k8s应用无关系
[root@master1 templates]# cat /root/helm/xianchao/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "xianchao.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "xianchao.name" . }}
helm.sh/chart: {{ include "xianchao.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "xianchao.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "xianchao.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
帮助手册
为模板中的每一个属性提供值
[root@master1 xianchao]# cat cat /root/helm/xianchao/values.yaml
replicaCount: 1
image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
hosts:
- host: chart-example.local
paths: []
tls: []
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
# 使用stable仓库,名称为memcached的chart,进行部署,部署的名称为memcached
# helm install --name memcached stable/memcached
# 部署
helm install /root/helm/xianchao
# 查看
kubectl get pods

helm list

helm package /root/helm/xianchao
生成的tgz包可以发送到任意服务器上,通过helm fetch就可以获取该chart

helm delete releaseName

helm repo list

# 先移除原先的仓库
helm repo remove stable
helm repo remove bitnami
# 添加repo
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
# 更新chart仓库
helm repo update
helm search

helm search mysql

helm inspect bitnami/mysql

helm upgrade
helm upgrade [RELEASE] [CHART] [flags]
helm rollback
helm rollback [flags] [RELEASE] [REVISION]
helm history releaseName
helm history wonderful-echidna

helm fetch chartName
helm fetch stable/rabbitmq-ha

helm install --debug --dry-run ./

Error: Couldn't load repositories file (/root/.helm/repository/repositories.yaml).
You might need to run `helm init` (or `helm init --client-only` if tiller is already installed)
mkdir -p /root/.helm/repository/
vi /root/.helm/repository/repositories.yaml
内容
apiVersion: v1
generated: 2019-04-03T21:52:41.714422328-04:00
repositories:
- caFile: ""
cache: /root/.helm/repository/cache/bitnami-index.yaml
certFile: ""
keyFile: ""
name: bitnami
password: ""
url: https://charts.bitnami.com/bitnami
username: ""
- caFile: ""
cache: /root/.helm/repository/cache/stable-index.yaml
certFile: ""
keyFile: ""
name: stable
password: ""
url: https://cnych.github.io/kube-charts-mirror
username: ""
# CA 证书文件
- caFile: ""
certFile: ""
# 缓存文件
cache: /root/.helm/repository/cache/local-repo-index.yaml
keyFile: ""
# 仓库名称
name: local-repo
# 用户密码
password: ""
username: ""
# 本地仓库地址,因为我们没有,这里就随便写
url: http://172.16.0.1:8879
- caFile: ""
cache: /root/.helm/repository/cache/local-index.yaml
certFile: ""
keyFile: ""
name: local
password: ""
url: http://127.0.0.1:8879/charts
username: ""
[root@master1 ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
Error: Looks like "https://charts.bitnami.com/bitnami" is not a valid chart repository or cannot be reached: open /root/.helm/repository/cache/bitnami-index.yaml: no such file or directory
mkdir -p /root/.helm/repository/cache

