搭建helm

在这里我们搭建helm的2.0版本

搭建client端

1.下载tar包

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.11.0-linux-amd64.tar.gz

2.将tar包解压

tar -zxvf helm-v2.11.0-linux-amd64.tar.gz

3.将解压出的二进制文件helm放到 /usr/local/bin 下面

搭建server端

1.部署tiller

helm init --upgrade -i \
 registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 \
--stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

2.查看tiller时候部署成功

# kubectl get pod -n kube-system |grep till
tiller-deploy-cd5cf5bb6-xbjfl           1/1       Running   0          2m

3.查看helm版本

# helm version
Client: &version.Version{SemVer:"v2.11.0", GitCommit:"2e55dbe1fdb5fdb96b75ff144a339489417b146b", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.11.0", GitCommit:"2e55dbe1fdb5fdb96b75ff144a339489417b146b", GitTreeState:"clean"}

搭建mysql

准备阶段

1.创建服务账号

kubectl create serviceaccount --namespace kube-system tiller

2.绑定集群角色

kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller

3.给应用程序设定账号

kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'

4.提供能够还未绑定的pv给mysql使用(如果k8s上有storageclass的话可以忽略这步)
这里的是基于nfs的pv,关于nfs的搭建在这里就累述了,百度一下都有。

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysqlpv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  nfs:
    path: /tmp
    server: 172.17.0.2

5.提供configmap用于mysql挂载使用


apiVersion: v1
data:
  mysqld.cnf: |-
    [mysqld]
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    datadir         = /var/lib/mysql
    #log-error      = /var/log/mysql/error.log
    # By default we only accept connections from localhost
    #bind-address   = 127.0.0.1
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    #如果你的sql语句里有group,添加这句可以防止报错
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    #避免表名大小写问题
    lower_case_table_names=1 
kind: ConfigMap
metadata:
  name: mysql-config
  namespace: gymdev

安装阶段

1.搜索能使用的mysql版本

helm search mysql
NAME                            CHART VERSION   APP VERSION     DESCRIPTION
stable/mysql                    0.3.5                           Fast, reliable, scalable, and easy to use open-source rel...
stable/percona                  0.3.0                           free, fully compatible, enhanced, open source drop-in rep...
stable/percona-xtradb-cluster   0.0.2           5.7.19          free, fully compatible, enhanced, open source drop-in rep...
stable/gcloud-sqlproxy          0.2.3                           Google Cloud SQL Proxy
stable/mariadb                  2.1.6           10.1.31         Fast, reliable, scalable, and easy to use open-source rel...

5.使用fetch的方式来进行安装,方便修改参数

helm fetch stable/mysql

6.得到一个tar包,解压

tar -zxvf mysql-0.3.5.tgz

7.修改mysql配置符合自己的需求

cd mysql

在values.yaml里面可以修改一些mysql的基本参数

vi values.yaml

这里介绍几个常用到的,比如说:

mysqlRootPassword: testing  ##root用户账号
## mysql关联pv的设置
## Persist data to a persistent volume
persistence:
  enabled: true
  ## database data Persistent Volume Storage Class
  ## If defined, storageClassName: <storageClass>
  ## If set to "-", storageClassName: "", which disables dynamic provisioning
  ## If undefined (the default) or set to null, no storageClassName spec is
  ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
  ##   GKE, AWS & OpenStack)
  ##
  # storageClass: "-"
  accessMode: ReadWriteOnce
  size: 3Gi (注意这里不能大于你创建的pv的大小)
## Configure the service
## ref: http://kubernetes.io/docs/user-guide/services/
service:
 ## Specify a service type
 ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types
 type: ClusterIP (如果你想在k8s外部访问该mysql那么改为NodePort,并且放开下面nodePort的注释)
 port: 3306  (k8s内部访问端口)
 # nodePort: 32000

8.将mysql配置文件挂载出来,方便后续对mysql进行修改

cd templates
vi deployment.yaml
volumeMounts:
- name: config-volume                      <--(挂载点名称)
  mountPath: "/etc/mysql/mysql.conf.d/"    <--(mysql配置文件路径)
volumes:
- name: config-volume                        <--(挂载点名称)
  configMap:                                 <--(使用configmap)
    name: mysql-config                       <--(configmap的名称)

9.安装mysql

helm install -n mysql -f values.yaml  .

10.查看mysql是否正常运行

kubectl get pod --all-namespaces
NAMESPACE          NAME                                                              READY     STATUS             RESTARTS   AGE
orz                mysql1-98c87576f-6t5t9                                            1/1       Running            1          37d

状态为Running,成功安装mysql。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐