首页 > 数据库 >kubernetes deploy standalone mysql demo

kubernetes deploy standalone mysql demo

时间:2023-09-07 16:04:12浏览次数:82  
标签:pv name standalone demo mysql 3306 spec metadata


kubernetes deploy standalone mysql demo_TCP

kubernetes 集群内部署 单节点 mysql

ansible all -m shell -a "mkdir -p /mnt/mysql/data"

cat mysql-pv-pvc.yaml

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

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:

kubectl apply -f mysql-pv-pvc.yaml
kubectl apply -f mysql-deploy.yaml

check

[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>

参考:


标签:pv,name,standalone,demo,mysql,3306,spec,metadata
From: https://blog.51cto.com/ghostwritten/7398137

相关文章

  • golang操作mysql
    golang操作mysql在Go语言中,你可以使用第三方库来进行MySQL数据库的操作。其中,比较常用的库有database/sql和github.com/go-sql-driver/mysql在安装了MySQL的前提下进行以下操作1下载依赖在终端执行命令:goget-ugithub.com/go-sql-driver/mysql2导入依赖库import(......
  • Mysql 数据库的数据大小查看
    Mysql数据库的数据大小查看:1、进入information_schema数据库(存放了其他的数据库的信息)mysql->useinformation_schema;2、查询所有数据的大小:mysql->selectconcat(round(sum(data_length/1024/1024),2),'MB')asdatafromtables;3、查看指定数据库的大小:比如查看数据库h......
  • MySQL数据库基础与实战应用
    ......
  • Ubentu 16.04.2 LTS安装mysql,jdk1.8
    一、网络设置1、网络设置sudovim/etc/network/interfaces文件中写入以下内容,写完后wq保存退出。#设置网卡名称autoeth0#设置静态IP,如果是使用自动IP用dhcp,后面的不用设置ifaceeth0inetstatic#设置IP地址addressxxx.xxx.xxx.xxx#设置子网掩码netmaskxxx.xxx.xxx.......
  • RK3568开发笔记(七):在宿主机ubuntu上搭建Qt交叉编译开发环境,编译一个Demo,目标板运行Demo
    前言  在之前的博文中已经搭建好了一个比较完善的ubuntu宿主机,都很完善了但是发现没有Qt交叉编译开发环境,所以还需要搭建一套Qt交叉编译开发环境。<br>补充说明  本篇是基于《RK3568开发笔记(三):RK3568虚拟机基础环境搭建之更新源、安装网络工具、串口调试、网络连接、文件传......
  • RK3568开发笔记(七):在宿主机ubuntu上搭建Qt交叉编译开发环境,编译一个Demo,目标板运行Demo
    前言  在之前的博文中已经搭建好了一个比较完善的ubuntu宿主机,都很完善了但是发现没有Qt交叉编译开发环境,所以还需要搭建一套Qt交叉编译开发环境。 补充说明  本篇是基于《RK3568开发笔记(三):RK3568虚拟机基础环境搭建之更新源、安装网络工具、串口调试、网络连接、......
  • 从MySQL全库备份中恢复某个库和某张表的方法
    一定要使用测试库操作一、全库备份恢复单个库的数据流程:1.第一种方法:--从全备中导出所需库的建库语句和INSERT语句。sed-n'/^--CurrentDatabase:`库名`/,/^--CurrentDatabase:`/p'全备.sql>test.sql--导入库,会自动建库mysql库名<test.sql2.另一种方法:mysql......
  • Linux系统安装jdk;tomcat;mysql。
    1安装jdk1:下载jdklinux环境jdk-8u161-linux-x64.tar.gz2:把下载好的软件放在linux系统中3:解压:tar-zxvfjdkXXXXX.tar.gz4:重命名:mvjdk1.8.0_161/jdk85:配置环境变量/etc/profile---->配置环境变量6:刷新/etc/profile文件source/etc/profile7:在任何目录输......
  • 【mysql】mysql判断某一张表是否存在的sql语句以及方法
    有四种方式进行判断: 1.--百分号中间为需要查询的表名SHOWTABLESLIKE‘%user%’;2. --dbname为数据库名字tablename为你需要查询的表名称,注意使用TEMPORARY关键字创建出来的临时表无法查询出来。selectTABLE_NAMEfromINFORMATION_SCHEMA.TABLESwhereTABL......
  • 【mysql】mysql分表分库
     MySQL按日期分表sql语句创建+XORM基于XORM框架实现分表MySQL数据库按时间分表的查询方法Mysqlunion与unionall究竟怎么用?到底有什么区别 #gorm分库分表https://gitee.com/lemontree/gorm-shardinghttps://blog.csdn.net/wyhstars/article/details/80609652http......