本文主要是介绍k8s学习(二十八) K8s部署单节点mysql-statefulset方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以下步骤的前提是已部署好storageclass,可参考https://blog.csdn.net/u011943534/article/details/100887530
1、下载mysql(已经下载好)
docker pull mysql:5.7
docker save -o mysql-5.7.tar mysql:5.7
2、导入镜像
将msyql-5.7.tar拷贝至K8s镜像服务器所在的节点
docker load -i mysql-5.7.tar
docker tag mysql:5.7 172.16.10.160:80/mysql:5.7
docker push 172.16.10.160:80/mysql:5.7
3、使用 kubectl apply -f mysql-server.yaml部署
---
apiVersion: apps/v1
kind: StatefulSet
metadata:name: mysqlnamespace: defaultlabels:app: mysqlversion: v1
spec:serviceName: "mysql"replicas: 1selector:matchLabels:app: mysqlversion: v1template:metadata:labels:app: mysqlversion: v1spec:containers:- name: mysqlimage: 172.16.10.160:80/mysql:5.7env: - name: MYSQL_ROOT_PASSWORDvalue: "root"ports:- containerPort: 3306volumeMounts:- name: mysql-datamountPath: /var/lib/mysql volumeClaimTemplates:- metadata:name: mysql-dataannotations:volume.beta.kubernetes.io/storage-class: course-nfs-storagespec:accessModes: [ "ReadWriteOnce" ]resources:requests:storage: 5Gi
---
apiVersion: v1
kind: Service
metadata:name: mysqlnamespace: defaultlabels:app: mysqlservice: mysql
spec:ports:- port: 3306protocol: TCPtargetPort: 3306name: tcpclusterIP: Noneselector:app: mysql---
apiVersion: v1
kind: Service
metadata:name: mysql2namespace: defaultlabels:app: mysql2service: mysql2
spec:ports:- name: tcpprotocol: TCPtargetPort: 3306port: 3306nodePort: 31112type: NodePortselector:app: mysql
4、查看pod
5、外部使用31112端口访问
如果无需外部访问,将31112对应的service删除。
内部使用headless的service访问(ClusterIP:None的)
这篇关于k8s学习(二十八) K8s部署单节点mysql-statefulset方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!