首页 > 数据库 >k8s运行单实例mysql

k8s运行单实例mysql

时间:2023-01-03 19:22:52浏览次数:60  
标签:name 19 999 Jan 实例 wgs mysql k8s

namespace

mysql-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
  labels:
    kubernetes.io/metadata.name: wgs-mysql
  name: wgs-mysql

创建ns

# kubectl apply -f mysql-ns.yaml 
namespace/wgs-mysql created

查看ns

# kubectl get ns wgs-mysql -o yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"labels":{"kubernetes.io/metadata.name":"wgs-mysql"},"name":"wgs-mysql"}}
  creationTimestamp: "2023-01-03T08:59:29Z"
  labels:
    kubernetes.io/metadata.name: wgs-mysql
  name: wgs-mysql
  resourceVersion: "1094074"
  uid: 54afc0a0-9070-4946-b74f-a8741479dbd0
spec:
  finalizers:
  - kubernetes
status:
  phase: Active

secret

mysql-secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: mysql-auth
  namespace: wgs-mysql
type: Opaque
data:
  username: cm9vdA==   # echo -n 'root' | base64
  password: MTIzNDU2   # echo -n '123456' | base64

创建secret

# kubectl apply -f mysql-secret.yaml 
secret/mysql-auth created

查看secret

# kubectl get secret -n wgs-mysql
NAME         TYPE     DATA   AGE
mysql-auth   Opaque   2      24s

pv

mysql-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  namespace: wgs-mysql
  labels:
    type: nfs
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    path: "/data/k8s-data/mysql"
    server: 192.168.174.102

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  namespace: wgs-mysql
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

创建pv

# kubectl apply -f mysql-pv.yaml 
persistentvolume/mysql-pv-volume created
persistentvolumeclaim/mysql-pv-claim created

查看pv

# kubectl get pv -n wgs-mysql
NAME              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                      STORAGECLASS   REASON   AGE
mysql-pv-volume   5Gi        RWO            Retain           Bound    wgs-mysql/mysql-pv-claim   manual                  108s
# kubectl get pvc -n wgs-mysql
NAME             STATUS   VOLUME            CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mysql-pv-claim   Bound    mysql-pv-volume   5Gi        RWO            manual         112s

mysql

mysql-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: wgs-mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql:5.7
          name: mysql
          env:
          - name: MYSQL_ROOT_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-pass
                key: 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


---


apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: wgs-mysql
spec:
  #type: NodePort
  ports:
  - port: 3306
   # targetPort: 3306
   # nodePort: 33306
  selector:
    app: mysql
  clusterIP: None

创建mysql资源

# kubectl apply -f mysql-deployment.yaml 
deployment.apps/mysql created
service/mysql created

查看mysql资源

# kubectl get pod -n wgs-mysql -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP               NODE              NOMINATED NODE   READINESS GATES
mysql-7487d69b7f-9p898   1/1     Running   0          35s   172.20.154.231   192.168.174.106   <none>           <none>
# kubectl get svc -n wgs-mysql
NAME    TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
mysql   ClusterIP   None         <none>        3306/TCP   51s

验证mysql

# kubectl exec -it  mysql-7487d69b7f-tf2rp -n wgs-mysql -- mysql -uroot -p123456 -e "show databases"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

查看pv数据

# ls -l mysql/
total 188476
-rw-r----- 1 999 999       56 Jan  3 19:08 auto.cnf
-rw------- 1 999 999     1680 Jan  3 19:08 ca-key.pem
-rw-r--r-- 1 999 999     1112 Jan  3 19:08 ca.pem
-rw-r--r-- 1 999 999     1112 Jan  3 19:08 client-cert.pem
-rw------- 1 999 999     1676 Jan  3 19:08 client-key.pem
-rw-r----- 1 999 999     1318 Jan  3 19:08 ib_buffer_pool
-rw-r----- 1 999 999 50331648 Jan  3 19:09 ib_logfile0
-rw-r----- 1 999 999 50331648 Jan  3 19:08 ib_logfile1
-rw-r----- 1 999 999 79691776 Jan  3 19:09 ibdata1
-rw-r----- 1 999 999 12582912 Jan  3 19:09 ibtmp1
drwxr-x--- 2 999 999     4096 Jan  3 19:08 mysql
lrwxrwxrwx 1 999 999       27 Jan  3 19:08 mysql.sock -> /var/run/mysqld/mysqld.sock
drwxr-x--- 2 999 999     4096 Jan  3 19:08 performance_schema
-rw------- 1 999 999     1680 Jan  3 19:08 private_key.pem
-rw-r--r-- 1 999 999      452 Jan  3 19:08 public_key.pem
-rw-r--r-- 1 999 999     1112 Jan  3 19:08 server-cert.pem
-rw------- 1 999 999     1680 Jan  3 19:08 server-key.pem
drwxr-x--- 2 999 999    12288 Jan  3 19:08 sys

标签:name,19,999,Jan,实例,wgs,mysql,k8s
From: https://www.cnblogs.com/wangguishe/p/17022754.html

相关文章

  • [clickhouse]同步MySQL
    前言clickhouse的查询速度非常快,而且兼容大部分MySQL的sql语法,因此一般将clickhouse作为MySQL的读库。本文提供两种clickhouse同步MySQL的方式clickhouse版本:21.2.4.6......
  • PCL库点云可视化与重建实例
    点云可视化|cloud_viewer​​cloudviewer实例​​pcd可视化|pcl_visualizer_demo​​pclvisualizerdemo实例​​ply可视化​​ply可视化实例​​读取.ply功能正常,显示ply点......
  • 软件开发入门教程网之MySQL 删除数据库
       ......
  • Mysql主从同步配置
    一、主数据库的配置1.my.cnf(Linux)/my.ini(Windows)在配置文件参数选项[mysqld]下面添加如下内容log_bin=mysql-binserver_id=1innodb_flush_log_at_trx_commit=......
  • k8s安装
    安装 openssh-server,提供远程连接sudoaptinstall-yopenssh-server 修改ssh配置文件 sudovi/etc/ssh/sshd_config允许root用户远程连接:PermitRootLoginye......
  • 微服务应用视角解读如何选择 K8s 的弹性策略
    头:潘俊峰前言微服务架构的出现,拆分了庞大的单体应用,让业务之间的开发与协作变得更加灵活。当面临业务流量增加的场景时,往往需要对一些应用组件进行扩容。K8s在应用层面提供......
  • mysql函数笔记
    count(*)计数avg()求一列的平均数distinct(q.device_id)对某一列去重,一般与count()连用count(question_id)/count(distinct(q.device_id))if(age>=25,'25岁及以上','25......
  • mysql 查询上月数据PERIOD_DIFF
    select*fromtable1wherePERIOD_DIFF(date_format(now(),'%Y%m'),date_format(fieldname,'%Y%m'))=1说明:查询table1的fieldname为上月的数据。PERIOD_DIFF()函......
  • 在linux上安装mysql(二进制,binary)
    1.去https://dev.mysql.com/downloads/file/?id=514030下载mysql-5.7.40-linux-glibc2.12-x86_64.tar,将它scp到目标机器上。保存到/root/tools/下; 2.执行如下命令,将......
  • 微服务应用视角解读如何选择 K8s 的弹性策略
    头:潘俊峰前言微服务架构的出现,拆分了庞大的单体应用,让业务之间的开发与协作变得更加灵活。当面临业务流量增加的场景时,往往需要对一些应用组件进行扩容。K8s在应用层面......