kubernetes之 why helm

一、why helm介绍

       kubernetes能够很好的组织和编排容器,但缺少一个更高层次的应用打包工具,而helm就是来干这件事的

      比如对于一个mysql服务,kubernetes需要部署下面的这些对象:

           1.service,让外界能够访问到mysql。

           2.secret,定义mysql的密码。

          3. persistentVolumeClaim,为mysql申请持久化储存空间。

          4.deployment,部署mysql  pod,并使用上面的这些支持对象。

    我们可以将上面这些配置保存到对象各自的文件中,或者集中写进一个配置文件,然后通过 kubectl apply  -f部署。

    到目前为止,kubernetes对服务的部署支持的都挺好,如果应用只由一个或几个这样的服务组成,上面的部署方式完全足够了。

二、helm架构

    helm有两个重要的概念: chart和 release。

helm客户端是终端用户使用的命令行工具,用户可以:

     

tiller服务器运行在kubernetes集群中,他会处理helm客户端的请求,与kubernetes api server交互。tiller服务器负责:

  

三、部署helm客户端

       1.下载安装包

wget  https://get.helm.sh/helm-v2.16.9-linux-amd64.tar.gz
cd linux-amd64/
cp helm  /usr/local/bin/
helm  version

    目前只能查到有很多子命令和参数,为了提高使用命令行的效率,通常建议安装helm的bash命令:

source <(helm completion bash)
echo "source <(helm completion bash)"  >> ~/.bashrc

       2.安装tiller服务器

helm init

   tiller本身也是作为容器话应用在kubernetes cluster中:

 可以看到tiller的service、deployment和pod

 可能会发生一下错误:

 解决办法:

docker pull sapcc/tiller:v2.16.8
docker tag sapcc/tiller:v2.16.8  gcr.io/kubernetes-helm/tiller:v2.16.8

四、使用helm

    1.    helm安装成功后,可执行 helm search查看当前可安装的chart

helm  search| more

  2.helm可以像apt和yum管理软件包一样管理chart,apt和yum的软件包存放在仓库中,同样helm也有仓库

helm  repo  list

        

 helm安装时已经默认配置好了两个仓库: stable和 local。stable是官方仓库,local是用户存放自己开发的chart本地仓库。

  3.  增加helm国内源:

helm repo remove  stable  (移除谷歌源)
helm repo add stable          http://mirror.azure.cn/kubernetes/charts/
helm repo add incubator       http://mirror.azure.cn/kubernetes/charts-incubator/ 添加国内源
helm  repo update  更新源

4.与apt和yum一样,helm也支持关键字搜索:

helm search mysql

包括description在内的所有信息,只要跟关键字匹配,都会显示在结果列表中。

5.安装chart也很简单。

helm install stable/mysql

  会发生以下错误:

           

  解决办法:看到这种报错,通常是因为tiller服务器的权限不足。执行命令添加权限:

[root@k8s-master ~]# kubectl create serviceaccount --namespace kube-system tiller
serviceaccount/tiller created
[root@k8s-master ~]# kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
clusterrolebinding.rbac.authorization.k8s.io/tiller-cluster-rule created
[root@k8s-master ~]# kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
deployment.apps/tiller-deploy patched

  2.错误点:

  和下载源有关系 更新下载源就可以了

helm repo add stable          http://mirror.azure.cn/kubernetes/charts/
helm repo add incubator       http://mirror.azure.cn/kubernetes/charts-incubator/

在此下载:

[root@k8s-master ~]# helm install  stable/mysql
NAME:   jaunty-bat
LAST DEPLOYED: Sat Aug  1 11:29:20 2020
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                   DATA  AGE
jaunty-bat-mysql-test  1     2s

==> v1/Deployment
NAME              READY  UP-TO-DATE  AVAILABLE  AGE
jaunty-bat-mysql  0/1    0           0          1s

==> v1/PersistentVolumeClaim
NAME              STATUS   VOLUME  CAPACITY  ACCESS MODES  STORAGECLASS  AGE
jaunty-bat-mysql  Pending  2s

==> v1/Pod(related)

==> v1/Secret
NAME              TYPE    DATA  AGE
jaunty-bat-mysql  Opaque  2     2s

==> v1/Service
NAME              TYPE       CLUSTER-IP   EXTERNAL-IP  PORT(S)   AGE
jaunty-bat-mysql  ClusterIP  10.96.191.0  <none>       3306/TCP  1s


NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
jaunty-bat-mysql.default.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default jaunty-bat-mysql -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 jaunty-bat-mysql -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/jaunty-bat-mysql 3306

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

6.  通过kubectl  get可以查看组成release的各个对象

由于还没有准备pervasiveVolume,当前release还不可用

7.删除rekease

helm list
helm delete jaunty-bat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值