11. kubernetes资源——configmap配置映射

一、configmap配置映射

  • 存放配置文件内容

1、创建configMap, 存MySQL配置

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]# 

2、创建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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值