• k8s--基础--25.3--Helm--常用命令和常见错误


    k8s–基础–25.3–Helm–常用命令和常见错误


    1、创建一个chart实例

    1. 在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
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    1.2、说明

    1.2.1、Chart.yaml

    1. 用来描述当前chart有哪属性信息,存放当前程序包的元数据信息,包的名字,版本等
    2. 跟部署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
    • 3
    • 4
    • 5
    • 6

    1.2.2、templates

    1. 模板
    2. 定义k8s的yaml文件,大量调用go语言的语法
    3. 跟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
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    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: {}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    2、常用命令

    2.1、部署k8s应用

     
    # 使用stable仓库,名称为memcached的chart,进行部署,部署的名称为memcached
    # helm install  --name memcached stable/memcached  
    
    # 部署
    helm install  /root/helm/xianchao
    
    # 查看
    kubectl get pods
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在这里插入图片描述

    2.2、查看有哪些release

    helm list 
    
    • 1

    在这里插入图片描述

    2.3、helm package 打包chart

    helm package /root/helm/xianchao
    
    
    • 1
    • 2

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

    在这里插入图片描述

    2.4、删除指定的release

    1. 删除指定的release(helm list查看到的)
    2. 同时删除了部署在kubernetes上的服务
    helm delete  releaseName
    
    • 1

    在这里插入图片描述

    2.5、查看chart仓库 列表

    helm repo list 
    
    
    • 1
    • 2

    在这里插入图片描述

    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   
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    2.7、查找所有的chart

    helm search
    
    
    • 1
    • 2

    在这里插入图片描述

    2.8、查找mysql chart

    helm search mysql
    
    
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    2.9、查看指定chart的详细信息

    helm inspect bitnami/mysql 
    
    • 1

    在这里插入图片描述

    2.10、升级一个版本

    helm upgrade
    helm upgrade [RELEASE] [CHART] [flags]
    
    
    • 1
    • 2
    • 3

    2.11、回滚一个版本

    
    helm rollback
    helm rollback [flags] [RELEASE] [REVISION]
    
    
    • 1
    • 2
    • 3
    • 4

    2.12、查看release历史

    
    helm  history releaseName
    
    helm  history wonderful-echidna
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    2.13、把chart下载下来

     
    helm  fetch chartName
    
    helm fetch stable/rabbitmq-ha
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述

    2.14、获取渲染后的yaml文件

     
    helm install --debug --dry-run ./
    
    • 1
    • 2

    在这里插入图片描述

    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)
    
    • 1
    • 2

    创建对应的目录

    mkdir -p /root/.helm/repository/
     
    
    • 1
    • 2

    创建repositories.yaml

    vi /root/.helm/repository/repositories.yaml
    
    • 1

    内容

    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: ""
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    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
    
    
    • 1
    • 2
    • 3

    创建目录

    mkdir -p /root/.helm/repository/cache
    
    • 1

    把下面文件拷贝到这个目录即可

    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    配置java和maven路径
    chatgpt赋能python:Python如何快速取出所有元素?
    OPENCV--实现meanshift图像分割
    服务器正文20:跨平台(win和linux)用cmake给程序增加汇编代码
    队列的链表实现 题目(难度1/10)
    考研数学一二三 2010-2019年每道题的难度系数
    金仓数据库KingbaseES客户端编程接口指南-ado.net(14. 示例)
    Batch_Normalization 、Layer_Normalization 、Group_Normalization你分的清楚吗
    Redis主从部署
    汽车区域控制器的关键技术和MCU解决方案深度分析
  • 原文地址:https://blog.csdn.net/zhou920786312/article/details/126243603