k8s ComfigMap mysql

发布于:2024-10-12 ⋅ 阅读:(132) ⋅ 点赞:(0)

创建ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
    name: test-mysql-config
data:
    test_my.cnf: |
         [mysqld]
         server_id=10
         log_bin=master
[root@k8s-master statefulTest]# kubectl create -f mysql-configmap.yaml
configmap/test-mysql-config created
[root@k8s-master statefulTest]# 
[root@k8s-master statefulTest]# kubectl get cm
NAME                DATA   AGE
kube-root-ca.crt    1      126d
test-mysql-config   1      11s
[root@k8s-master statefulTest]# 
[root@k8s-master statefulTest]# kubectl describe cm test-mysql-config
Name:         test-mysql-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
test_my.cnf:
----
[mysqld]
server_id=10
log_bin=master


BinaryData
====

Events:  <none>
[root@k8s-master statefulTest]# 

创建MySQL pod

apiVersion: apps/v1
kind: StatefulSet
metadata:
    name: test-mysql
spec:
    replicas: 1
    selector:
        matchLabels:
            app: mysql
    serviceName: "test-mysql"
    template:
        metadata:
            labels:
               app: mysql
        spec:
            containers:
            - name: test-mysql
              image: mysql:5.7
              imagePullPolicy: IfNotPresent
              env:
              - name: MYSQL_ROOT_PASSWORD
                value: redhat
              volumeMounts:
                 - name: mysql-data-volume
                   mountPath: /var/lib/mysql
                 - name: mysql-config-volume
                   mountPath: "/etc/mysql/conf.d/"
                   readOnly: true
            volumes:
              - name: mysql-data-volume
                persistentVolumeClaim:
                    claimName: db-pvc-5g
              - name: mysql-config-volume					// 创建数据卷,存放MySQL配置文件
                configMap:
                    name: test-mysql-config
---
apiVersion: v1
kind: Service
metadata:
    name: test-mysql
spec:
    ports:
    - port: 3306
    selector:
        app: mysql



网站公告

今日签到

点亮在社区的每一天
去签到