本文作者:丁辉
部署Mysql
本文内容
- StatefulSet 单实例部署
- Cmd检测
- Volumes 持久化挂载Nfs
- 使用 NetworkPolicy 允许其他namespace pod 连接
记得准备一个 Nfs 存储或者自己修改一下 volumes 喔
开始部署
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| apiVersion: apps/v1 kind: StatefulSet metadata: namespace: offends name: mysql spec: replicas: 1 serviceName: mysql-service selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: root volumeMounts: - mountPath: /var/lib/mysql name: data-volume ports: - containerPort: 3306 protocol: TCP livenessProbe: exec: command: - mysql - --user=root - --password=root - --execute=SELECT 1 initialDelaySeconds: 10 periodSeconds: 10 volumes: - name: data-volume nfs: server: path: readOnly: false --- apiVersion: v1 kind: Service metadata: namespace: offends name: mysql-service spec: type: NodePort selector: app: mysql ports: - name: mysql protocol: TCP port: 3306 targetPort: 3306 nodePort: 30000
|
1
| kubectl apply -f mysql.yaml
|
NetworkPolicy
flannel似乎不支持,我不太懂哈写的不对别怪我
1
| vi allow-mysql-service.yaml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-mysql-service namespace: offends spec: ingress: - from: - namespaceSelector: matchLabels: app: ports: - protocol: TCP port: 3306 podSelector: matchLabels: app: mysql policyTypes: - Ingress
|
部署
1
| kubectl apply -f allow-mysql-service.yaml
|