kubernetes deploy standalone mysql demo

kubernetes 集群内部署 单节点 mysql

bash 复制代码
ansible all -m shell -a "mkdir -p /mnt/mysql/data"

cat mysql-pv-pvc.yaml

bash 复制代码
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/mysql/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

cat mysql-deploy.yaml

bash 复制代码
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  type: NodePort
  ports:
  - port: 3306
    nodePort: 30006
    targetPort: 3306
    protocol: TCP
  selector:
    app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim

start:

bash 复制代码
kubectl apply -f mysql-pv-pvc.yaml
kubectl apply -f mysql-deploy.yaml

check

bash 复制代码
[root@kube-master01 mysql]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
mysql-794c6d56c6-xnfhb   1/1     Running   0          10h
[root@kube-master01 mysql]# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.43.0.1      <none>        443/TCP          23d
mysql        NodePort    10.43.17.172   <none>        3306:30006/TCP   10h
mysql        NodePort    10.43.17.172   <none>        3306:30006/TCP   10h
[root@kube-master01 mysql]# mysql -h 192.168.23.31 -P 30006 -u root -p'password'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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 |
| clusterpedia       |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.05 sec)

mysql>

参考:

相关推荐
知识的宝藏6 分钟前
Django models中的增删改查与MySQL SQL的对应关系
sql·mysql·django·django models
路在脚下@6 分钟前
MySQL的索引失效的原因有那些
数据库·mysql
新子-存在了33 分钟前
linux中 mysql备份
linux·运维·mysql
vvw&2 小时前
如何在 Ubuntu 22.04 上安装 phpMyAdmin
linux·运维·服务器·mysql·ubuntu·php·phpmyadmin
奥顺互联V3 小时前
深入理解 ThinkPHP:框架结构与核心概念详解
大数据·mysql·开源·php
MrJson-架构师4 小时前
4.银河麒麟V10(ARM) 离线安装 MySQL
arm开发·mysql
运维&陈同学4 小时前
【Beats01】企业级日志分析系统ELK之Metricbeat与Heartbeat 监控
运维·elk·elasticsearch·云原生·kibana·heartbeat·metricbeat
AKA小徐5 小时前
Debian12使用RKE2离线部署3master2node三主两从的k8s集群详细教程
kubernetes·rancher·rke2
夜半被帅醒5 小时前
MySQL 数据库优化详解【Java数据库调优】
java·数据库·mysql
不爱学习的啊Biao5 小时前
【13】MySQL如何选择合适的索引?
android·数据库·mysql