k8s--基础--25.3--Helm--常用命令和常见错误
生成的tgz包可以发送到任意服务器上,通过helm fetch就可以获取该chart。为模板中的每一个属性提供值。
·
k8s–基础–25.3–Helm–常用命令和常见错误
1、创建一个chart实例
- 在master1上操作
1.1、创建一个chart实例
[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
1.2、说明
1.2.1、Chart.yaml
- 用来描述当前chart有哪属性信息,存放当前程序包的元数据信息,包的名字,版本等
- 跟部署k8s应用无关系,只是记录chart的信息的
[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应用无关系
1.2.2、templates
- 模板
- 定义k8s的yaml文件,大量调用go语言的语法
- 跟ansible的playbook一样,ansible的playbook也可以使用模板
[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 }}
1.2.3、README.md
帮助手册
1.2.4、values.yaml
为模板中的每一个属性提供值
[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: {}
2、常用命令
2.1、部署k8s应用
# 使用stable仓库,名称为memcached的chart,进行部署,部署的名称为memcached
# helm install --name memcached stable/memcached
# 部署
helm install /root/helm/xianchao
# 查看
kubectl get pods

2.2、查看有哪些release
helm list

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

2.4、删除指定的release
- 删除指定的release(helm list查看到的)
- 同时删除了部署在kubernetes上的服务
helm delete releaseName

2.5、查看chart仓库 列表
helm repo list

2.6、添加chart仓库
# 先移除原先的仓库
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
2.7、查找所有的chart
helm search

2.8、查找mysql chart
helm search mysql

2.9、查看指定chart的详细信息
helm inspect bitnami/mysql

2.10、升级一个版本
helm upgrade
helm upgrade [RELEASE] [CHART] [flags]
2.11、回滚一个版本
helm rollback
helm rollback [flags] [RELEASE] [REVISION]
2.12、查看release历史
helm history releaseName
helm history wonderful-echidna

2.13、把chart下载下来
helm fetch chartName
helm fetch stable/rabbitmq-ha

2.14、获取渲染后的yaml文件
helm install --debug --dry-run ./

3、常见错误
3.1、Error: stat /root/.helm/repository/local: no such file or directory
3.2、Couldn’t load repositories file (/root/.helm/repository/repositories.yaml).
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/
创建repositories.yaml
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: ""
3.3、执行helm repo add bitnami https://charts.bitnami.com/bitnami报错
[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
把下面文件拷贝到这个目录即可


更多推荐



所有评论(0)