当前位置:网站首页>Getting started with k8s: building MySQL with Helm
Getting started with k8s: building MySQL with Helm
2022-07-02 08:33:00 【Don't understand for a while】
One 、 Series articles
Chapter one : k8s introduction : Bare metal deployment k8s colony
Chapter two : k8s introduction : Deploy the application to k8s colony
The third chapter : k8s introduction :service Easy to use
Chapter four : k8s introduction :StatefulSet Easy to use
The fifth chapter : k8s introduction : Storage (storage)
Chapter six : K8S To configure storageclass Use nfs Dynamically claim local disk space
Chapter vii. : k8s introduction : To configure ConfigMap & Secret
Chapter viii. : k8s introduction :k8s introduction :Helm structure MySQL
Chapter nine : k8s introduction :kubernetes-dashboard install
Chapter ten : k8s introduction :kube-prometheus-stack The whole family can build (Grafana + Prometheus)
List of articles
Two 、 brief introduction
Helm similar npm,pip,docker hub, It can be understood as a software library , You can easily and quickly install some third-party software for our cluster .Helm Is to find 、 Share and use software to build Kubernetes The best way . Use Helm We can build it very conveniently MongoDB / MySQL Replica clusters ,YAML Others have written the documents for us , Use it directly
Helm Official website :https://helm.sh/zh/docs/
Helm chart Warehouse Artifact Hub :https://artifacthub.io/packages/search
Artifact Hub Is based on web Page application , Support CNCF Finding items 、 Install and release packages and configuration items , Including publicly released Helm chart. It is CNCF Sandbox project
Environmental Science :
- linux:centos 7.9
- helm:v3.9.0
- docker:v20.10.17
- k8s:v1.23.1
- MySQL:v8.0.29
- MySQL chart:9.1.8
3、 ... and 、 Three concepts
Chart: Represents the Helm package . It is contained in Kubernetes Running applications inside the cluster , All resource definitions required for a tool or service .
Repository( Warehouse ): It's for storing and sharing charts The place of , for Kubernetes What the package uses .
Release: Is running on the Kubernetes In the cluster chart Example . One chart It can usually be installed multiple times in the same cluster . every last chart All have their own release and release name.
Helm install charts To Kubernetes In the cluster , Each installation creates a new release. You can Helm Of chart repositories Looking for new chart.
Four 、 Common commands
- helm search: lookup Charts, You can go straight to Artifact Hub Search the website charts, helm search hub from Artifact Hub Find and list helm charts ,Helm The search uses a fuzzy string matching algorithm , So you can just type in part of the name
- helm search hub - stay Artifact Hub Or your own hub Search for chart
- helm search repo - Search in the warehouse you added
- helm install: To install a helm package , The simplest way to use it is to pass in two parameters : You named it release Name and what you want to install chart The name of .
- helm upgrade and helm rollback: upgrade release And recover on failure
- helm uninstall: uninstall release
- helm repo:Helm 3 No longer comes with a default chart Warehouse .helm repo Provides a set of commands to add (helm repo add)、 List (helm repo list)、 to update (helm repo update) And remove the warehouse (helm repo remove).
For more detailed commands, please refer to :https://helm.sh/zh/docs/helm/helm/
5、 ... and 、 practice :helm install mysql
1、 install helm
Automated script installation
install helm, Now use the script to install helm 3, For more installation methods, please refer to :https://helm.sh/zh/docs/intro/install/
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
Compression pack installation
- download Version needed :https://github.com/helm/helm/releases
- decompression (
tar -zxvf helm-v3.9.0-linux-amd64.tar.gz
) - Find... In unzip helm Program , Move to the desired directory (mv linux-amd64/helm /usr/local/bin/helm)
2、 add to chart Warehouse
# Heavenly Sword bitnami Warehouse
[[email protected] secret]# helm repo add bitnami https://charts.bitnami.com/bitnami
# Add open source /Azure China
[[email protected] secret]# helm repo add azure http://mirror.azure.cn/kubernetes/charts/
# View the added warehouse
[[email protected] secret]# helm repo list
NAME URL
azure http://mirror.azure.cn/kubernetes/charts/
bitnami https://charts.bitnami.com/bitnami
3、 Inquire about mysql Available version
Find out what's available MySQL, You can go to Helm chart Warehouse Artifact Hub Find available MySQL, Such as :https://artifacthub.io/packages/helm/bitnami/mysql, You can also use the following command to find
# Inquire about Artifact Hub Available in mysql chart
[[email protected] secret]# helm search hub mysql
URL CHART VERSION APP VERSION DESCRIPTION
https://artifacthub.io/packages/helm/cloudnativ... 5.0.1 8.0.16 Chart to create a Highly available MySQL cluster
https://artifacthub.io/packages/helm/stakater/m... 1.0.6 mysql chart that runs on kubernetes
https://artifacthub.io/packages/helm/saber/mysql 8.8.21 8.0.27 Chart to create a Highly available MySQL cluster
# Inquire about repo Warehouse available mysql chart
[[email protected] secret]# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
azure/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
bitnami/mysql 9.1.8 8.0.29 MySQL is a fast, reliable, scalable, and easy t...
4、 install MySQL
①、 Optional parameters
install MySQL, For more detailed parameters, please refer to https://artifacthub.io/packages/helm/bitnami/mysql
Parameters | explain | The default value is |
MySQL Common parameters | ||
auth.rootPassword | root Account password | "" |
auth.createDatabase | establish auth.database Specified database | true |
auth.database | Database name | my_database |
MySQL Main parameters | ||
primary.persistence.storageClass | MySQL Host the long volume storage class | "" |
primary.persistence.annotations | MySQL Host long volume statement notes | {} |
primary.persistence.accessModes | MySQL Host long volume access mode | ["ReadWriteOnce"] |
primary.persistence.size | MySQL Host long volume size | 8Gi |
MySQL Auxiliary parameter | ||
secondary.service.type | service type | ClusterIP |
secondary.service.ports.mysql | service port | 3306 |
secondary.service.nodePorts.mysql | service nodePorts | "" |
②、 Parameter file
config.yaml The contents of the document are as follows ,YAML yes JSON Superset , You can also use JSON file
auth:
createDatabase: true
database: "study_database"
rootPassword: "[email protected]"
primary:
service:
ports:
mysql: "3306"
type: "NodePort"
nodePorts:
mysql: "33060"
persistence:
storageClass: "nfs-storage"
size: "1Gi"
annotations: {
}
accessModes:
- "ReadWriteMany"
enabled: true
③、storageClass
among primary.persistence.storageClass=“nfs-storage” as follows , For specific implementation, please refer to another article :K8S To configure storageclass Use nfs Dynamically claim local disk space
[[email protected] mysql]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-storage nfs-diy Retain Immediate false 6d20h
[[email protected] mysql]# kubectl describe sc/nfs-storage
Name: nfs-storage
IsDefaultClass: No
Annotations: kubectl.kubernetes.io/last-applied-configuration={
"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{
"annotations":{
},"name":"nfs-storage"},"parameters":{
"archiveOnDelete":"false"},"provisioner":"nfs-diy","reclaimPolicy":"Retain"}
Provisioner: nfs-diy
Parameters: archiveOnDelete=false
AllowVolumeExpansion: <unset>
MountOptions: <none>
ReclaimPolicy: Retain
VolumeBindingMode: Immediate
Events: <none>
④、 install MySQL chart
# install MySQL,-f config.yaml Specify the parameter file
[[email protected] mysql]# helm install mysql bitnami/mysql -f config.yaml
NAME: mysql
LAST DEPLOYED: Mon Jun 27 19:05:45 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 9.1.8
APP VERSION: 8.0.29
** Please be patient while the chart is being deployed **
Tip:
Watch the deployment status using the command: kubectl get pods -w --namespace default
Services:
echo Primary: mysql.default.svc.cluster.local:3306
Execute the following to get the administrator credentials:
echo Username: root
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql -o jsonpath="{.data.mysql-root-password}" | base64 -d)
To connect to your database:
1. Run a pod that you can use as a client:
kubectl run mysql-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.29-debian-11-r3 --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash
2. To connect to primary service (read/write):
mysql -h mysql.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"
# see pod details
[[email protected] mysql]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mysql-0 1/1 Running 0 105s 10.244.1.57 node1 <none> <none>
# see PVC
[[email protected] mysql]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-mysql-0 Bound pvc-e9484bd1-9ec2-4f09-8d71-d7bd1342792b 1Gi RWX nfs-storage 15s
# see PV
[[email protected] mysql]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-9e1650f2-4f5b-4c14-95c2-eb046ebddb2c 8Gi RWO Retain Released default/data-mysql-0 nfs-storage 85m
# Mounted Directory
[[email protected] mysql]# ls /home/data/default-data-mysql-0-pvc-e9484bd1-9ec2-4f09-8d71-d7bd1342792b/data/
auto.cnf binlog.000002 binlog.index ca.pem client-key.pem #ib_16384_1.dblwr ibdata1 ib_logfile1 #innodb_temp mysql.ibd performance_schema public_key.pem server-key.pem sys undo_002
binlog.000001 binlog.000003 ca-key.pem client-cert.pem #ib_16384_0.dblwr ib_buffer_pool ib_logfile0 ibtmp1 mysql mysql_upgrade_info private_key.pem server-cert.pem study_database undo_001
# see SVC
[[email protected] mysql]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysql NodePort 10.96.52.109 <none> 3306:33060/TCP 26s
mysql-headless ClusterIP None <none> 3306/TCP 26s
⑤、 Connect the test
- The command line connection is as follows , You can see that the connection is successful , And create study_database database
# Create a MySQL pod, Exit to delete
[[email protected] mysql]# kubectl run mysql-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.29-debian-11-r3 --namespace default --env [email protected] --command -- bash
If you don't see a command prompt, try pressing enter. I have no [email protected]:/$ mysql -h mysql.default.svc.cluster.local -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 352 Server version: 8.0.29 Source distribution Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| study_database |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
- Visual interface sqlyog Successful connection , Port number 33060
5、 uninstall mysql
Uninstall using the following command mysql, Will delete pod and service, But it will not be deleted PV 、 PVC and SC,PV The state will change to Released
[[email protected] mysql]# helm uninstall mysql
release "mysql" uninstalled
边栏推荐
- Use Matplotlib to draw a preliminary chart
- File upload Labs
- Summary of one question per day: String article (continuously updated)
- STM32 new project (refer to punctual atom)
- Don't know mock test yet? An article to familiarize you with mock
- [dynamic planning] p4170: coloring (interval DP)
- One of the reasons for WCF update service reference error
- Force buckle method summary: sliding window
- How to uninstall SQL Server cleanly
- 类和对象(类和类的实例化,this,static关键字,封装)
猜你喜欢
VS Code配置问题
Comparable,Comparator,Clonable 接口使用剖析
OpenCV3 6.3 用滤波器进行缩减像素采样
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
Simple implementation scheme of transcoding and streaming (I)
File upload and download performance test based on the locust framework
HCIA—数据链路层
CarSim problem failed to start solver: path_ ID_ OBJ(X) was set to Y; no corresponding value of XXXXX?
Honeypot attack and defense drill landing application scheme
sqli-labs第8关(布尔盲注)
随机推荐
类和对象(类和类的实例化,this,static关键字,封装)
Opencv common method source link (continuous update)
C language custom types - structure, bit segment (anonymous structure, self reference of structure, memory alignment of structure)
C language implements XML generation and parsing library (XML extension)
Use C language to receive JSON strings
OpenCV常用方法出处链接(持续更新)
OpenFeign 简单使用
Constant pointer and pointer constant
On November 24, we celebrate the "full moon"
Use Wireshark to grab TCP three handshakes
ICMP Protocol
What is SQL injection
Force deduction method summary: find classes
The best blog to explain the basics of compilation (share)
SQL操作数据库语法
链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
Principes fondamentaux de la théorie musicale (brève introduction)
Library function of C language
STL quick reference manual
Routing foundation - dynamic routing