cloud
cloud-native
云原生与 kubernetes
部署中间件
Mysql

部署 ElasticSearch(8.x)

ES 8.7

部署说明:通过 nodeSelector 固定到 worker3 节点上。并使用 worker3 上的原生文件系统目录 /.data

部署文件说明

  1. 通过环境变量指定 Mysql 密码等
  2. 通过 config 定制 mysqld.conf 的配置, 比如 0.0.0.0 外部网络访问
  3. 有使用 LoadBalancer 类型的 Service, 通过 externalIPs 指定外部 IP
  4. 通过 hostPath 挂载宿主机的目录, 用于持久化数据提升IO性能
  5. 部署于 middleware 命名空间
  6. 镜像使用 registry.cn-hongkong.aliyuncs.com/jansora/mysql:8.0.35, 拷贝自官方镜像,无改动
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql-1
  namespace: middleware
spec:
  selector:
    matchLabels:
      app: mysql-1
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql-1
    spec:
      nodeSelector:
        worker: worker3
      containers:
        - name: mysql-1
          image: registry.cn-hongkong.aliyuncs.com/jansora/mysql:8.0.35
          imagePullPolicy: IfNotPresent
          env:
            - name: MYSQL_ROOT_HOST
              value: '%'
            - name: MYSQL_ROOT_PASSWORD
              value: '256dac22d6458e094ff03d79d30f6ad2'
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: host-path
              subPath: 'mysql/mysql-1/data'
              mountPath: "/var/lib/mysql"
            - name: config-volume
              mountPath: /etc/mysql/conf.d/mysqld.cnf # 具体路径请参考官方文档
              subPath: mysqld.cnf
      volumes:
        - name: config-volume
          configMap:
            name: mysql-config
        - name: host-path
          hostPath:
            path: /.data/
            type: DirectoryOrCreate
  serviceName: mysql-1-service
 
---
 
# 创建 Service 由 kubernetes 来对多个 nameserver 做负载均衡
apiVersion: v1
kind: Service
metadata:
  labels:
    app: mysql-1
  name: mysql-1-service
  namespace: middleware
spec:
  type: LoadBalancer
  externalIPs:
    - 192.168.36.12
  ports:
    - port: 3306
      protocol: TCP
  selector:
    app: mysql-1
 
---
 
 
# 创建 configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-config
  namespace: middleware
data:
  mysqld.cnf: |
    [mysqld]
    lower_case_table_names=1
    bind-address = 0.0.0.0
    max_connections        = 500