第18章helm
1.Helm介绍
Helm就是k8s的软件包管理工具,好比是Centos的yum。

2.Helm基础配置
官方网址:
安装helm
wget https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz
tar zxf helm-v3.6.3-linux-amd64.tar.gz -C /opt/
cp /opt/linux-amd64/helm /usr/local/bin/
helm version
仓库指南
https://artifacthub.io/packages/search?kind=0
添加仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add stable https://charts.helm.sh/stable
查看仓库列表
helm repo list
更新helm仓库
helm repo update
3.helm安装服务
查找软件
helm search repo nginx
查看软件信息
helm show chart bitnami/nginx
helm show all bitnami/nginx
安装软件
helm install nginx bitnami/nginx
helm install bitnami/nginx --generate-name
查看已经部署的版本
helm list
查看已经安装的软件信息
helm status nginx-xxxx
卸载软件
helm uninstall nginx-xxxx
命令补全
source <(helm completion bash)
echo "source <(helm completion bash)" >>  ~/.bash_profile
4.helm定制安装参数
查看可以配置的参数
helm show values bitnami/nginx
自定义values文件
5.helm安装软件方式
helm install命令支持从多种源来进行安装:
在线chart仓库
helm install nginx bitnami/nginx
下载到本地的chart压缩包
下载到本地的chart解压缩后的包
在线的chart压缩包
6.helm升级和回滚
升级操作
语法格式:
helm upgrade [RELEASE] [CHART] [flags]
操作案例:
helm upgrade -f config.yaml mysql stable/mysql
查看是否生效:
helm get values mysql
回滚操作
语法格式
helm rollback <RELEASE> [REVISION] [flags]
操作案例:
helm rollback mysql 1
x.helm案例
helm部署mysql
image: "luffy.com/base/mysql"
imageTag: "5.7"
mysqlRootPassword: luffy
mysqlUser: luffy
mysqlPassword: luffy
mysqlDatabase: luffy
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor-secret
persistence:
  enabled: true
  storageClass: "localpv"
  accessMode: ReadWriteOnce
  size: 5Gi
resources:
  requests:
    memory: 256Mi
    cpu: 100m
service:
  type: ClusterIP
  port: 3306
helm部署jenkins
#工作目录
jenkinsHome: /bitnami/jenkins/home
#镜像地址
image:
  registry: luffy.com
  repository: base/jenkins
  tag: 2.44
  pullPolicy: IfNotPresent
  pullSecrets: [harbor-secret]
#pv相关
persistence:
  enabled: true
  storageClass: "localpv"
  accessModes:
    - ReadWriteOnce
  size: 5Gi
#ingress相关
ingress:
  enabled: true
  pathType: ImplementationSpecific
  hostname: jenkins.local
  ingressClassName: "nginx"
  path: /
  tls: false
#service相关
service:
  type: ClusterIP
  ports:
    http: 80
    https: 443
helm部署elasticsearch集群
添加仓库
helm repo add elastic https://helm.elastic.co
获取values配置(注意版本要对应上)
helm show values elastic/elasticsearch --version 7.17.3 > es-values-7.yaml
创建localpv
apiVersion: v1
kind: PersistentVolume
metadata:
  name: localpv01
  labels:
    type: localpv
spec:
  storageClassName: localpv
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: "/data/es"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - master-01
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: localpv02
  labels:
    type: localpv
spec:
  storageClassName: localpv
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: "/data/es"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-01
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: localpv03
  labels:
    type: localpv
spec:
  storageClassName: localpv
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: "/data/es"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - node-02
编辑values
#集群配置
clusterName: "elasticsearch"
nodeGroup: "master"
#节点数量
replicas: 3
#镜像配置
image: "luffy.com/base/elasticsearch"
imageTag: "7.17.3"
imagePullPolicy: "IfNotPresent"
imagePullSecrets:
  - name: harbor-secret
#资源限制
resources:
  requests:
    cpu: "100m"
    memory: "512Mi"
  limits:
    cpu: "100m"
    memory: "512Mi"
persistence:
  enabled: true
#pvc模版
volumeClaimTemplate:
  accessModes: ["ReadWriteOnce"]
  storageClassName: localpv
  resources:
    requests:
      storage: 5Gi
#容忍
tolerations:
- operator: "Exists"
  effect: "NoSchedule"
#service
service:
  enabled: true
  type: ClusterIP
  httpPortName: http
  transportPortName: transport
#ingress
ingress:
  enabled: true
  className: "nginx"
  pathtype: ImplementationSpecific
  hosts:
    - host: es.local
      paths:
        - path: /
#就绪探针
readinessProbe:
  initialDelaySeconds: 30
  periodSeconds: 10
创建命令
#!/bin/bash
helm install es -f values-elasticsearch.yaml --version 7.17.3 elastic/elasticsearch
helm部署ingress
更新: 2024-09-24 14:57:34