安装Helm

一、简介

什么是 Helm Helm 为团队提供了在 Kubernetes 内部创建、安装和管理应用程序时需要协作的工具,有点类似于 Ubuntu 中的 APT 或 CentOS 中的 YUM。

有了 Helm,开发者可以:

  • 查找要安装和使用的预打包软件(Chart)

  • 轻松创建和托管自己的软件包

  • 将软件包安装到任何 K8s 集群中

  • 查询集群以查看已安装和正在运行的程序包

  • 更新、删除、回滚或查看已安装软件包的历史记录

Helm 组件和相关术语

helm

  • Helm 是一个命令行下的客户端工具。主要用于 Kubernetes 应用程序 Chart 的创建、打包、发布以及创建和管理本地和远程的 Chart 仓库。

Chart

  • Helm 的软件包,采用 TAR 格式。类似于 APT 的 DEB 包或者 YUM 的 RPM 包,其包含了一组定义 Kubernetes 资源相关的 YAML 文件。

Repoistory

  • Helm 的软件仓库,Repository 本质上是一个 Web 服务器,该服务器保存了一系列的 Chart 软件包以供用户下载,并且提供了一个该 Repository 的 Chart 包的清单文件以供查询。Helm 可以同时管理多个不同的 Repository。

Release

  • 使用 helm install 命令在 Kubernetes 集群中部署的 Chart 称为 Release。可以理解为 Helm 使用 Chart 包部署的一个应用实例。

 

二、安装helm

地址 https://helm.sh/docs/intro/install/

# wget https://get.helm.sh/helm-v3.3.4-linux-amd64.tar.gz

# tart -zxvf helm-v3.3.4-linux-amd64.tar.gz 

# mv linux-amd64/helm /usr/local/bin/helm

# helm version
version.BuildInfo{Version:"v3.3.4", GitCommit:"a61ce5633af99708171414353ed49547cf05013d", GitTreeState:"clean", GoVersion:"go1.14.9"}

  

命令补全

# vim ~/.bashrc
source <(helm completion bash)

# source ~/.bashrc

  

三、使用

3.1 添加常用仓库

$ helm repo add stable https://kubernetes-charts.storage.googleapis.com/
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm repo update # Make sure we get the latest list of charts
$ helm repo add ali-stable    https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts  #阿里云

  

#  helm repo list
NAME         	URL                                                        
ingress-nginx	https://kubernetes.github.io/ingress-nginx                 
stable       	https://kubernetes-charts.storage.googleapis.com/          
bitnami      	https://charts.bitnami.com/bitnami                         
incubator    	https://kubernetes-charts-incubator.storage.googleapis.com/

  

3.2 安装一个mysql的chart

# helm install stable/mysql --generate-name
NAME: mysql-1604294571
LAST DEPLOYED: Mon Nov  2 13:22:54 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysql-1604294571.default.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1604294571 -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

To connect to your database:

1. Run an Ubuntu pod that you can use as a client:

    kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il

2. Install the mysql client:

    $ apt-get update && apt-get install mysql-client -y

3. Connect using the mysql cli, then provide your password:
    $ mysql -h mysql-1604294571 -p

To connect to your database directly from outside the K8s cluster:
    MYSQL_HOST=127.0.0.1
    MYSQL_PORT=3306

    # Execute the following command to route the connection:
    kubectl port-forward svc/mysql-1604294571 3306

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}

  

我们需要创建一个pvc,挂载到mysql这个pod中,才能起来mysql

创建storageClass

mysql-sc.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: mysql-sc
# Change "rook-ceph" provisioner prefix to match the operator namespace if needed
provisioner: rook-ceph.rbd.csi.ceph.com
parameters:
    # clusterID is the namespace where the rook cluster is running
    clusterID: rook-ceph
    # Ceph pool into which the RBD image shall be created
    pool: replicapool

    # RBD image format. Defaults to "2".
    imageFormat: "2"

    # RBD image features. Available for imageFormat: "2". CSI RBD currently supports only `layering` feature.
    imageFeatures: layering

    # The secrets contain Ceph admin credentials.
    csi.storage.k8s.io/provisioner-secret-name: rook-csi-rbd-provisioner
    csi.storage.k8s.io/provisioner-secret-namespace: rook-ceph
    csi.storage.k8s.io/controller-expand-secret-name: rook-csi-rbd-provisioner
    csi.storage.k8s.io/controller-expand-secret-namespace: rook-ceph
    csi.storage.k8s.io/node-stage-secret-name: rook-csi-rbd-node
    csi.storage.k8s.io/node-stage-secret-namespace: rook-ceph

    # Specify the filesystem type of the volume. If not specified, csi-provisioner
    # will set default as `ext4`. Note that `xfs` is not recommended due to potential deadlock
    # in hyperconverged settings where the volume is mounted on the same node as the osds.
    csi.storage.k8s.io/fstype: ext4

# Delete the rbd volume when a PVC is deleted
reclaimPolicy: Delete

  

创建pvc

mysql-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-1604294571
spec:
  storageClassName: mysql-sc
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

  

查看mysql启动情况

# kubectl get po
NAME                                READY   STATUS    RESTARTS   AGE
mysql-1604294571-69d68bb95b-2mx6p   1/1     Running   0          38m

  

查看使用helm安装的Release(有namespace区分)

# helm list
NAME            	NAMESPACE	REVISION	UPDATED                                	STATUS    CHART      	APP VERSION
mysql-1604294571	default  	1       	2020-11-02 13:22:54.106827838 +0800 CST	deployed  mysql-1.6.7	5.7.30

  

卸载

# helm uninstall mysql-1604294571

  

posted @ 2020-11-04 14:58  Bigberg  阅读(10446)  评论(0编辑  收藏  举报