k8s部署webstack(storageclass方式)
前言:
部署MySql时无法自动创建webstack数据库 此时需要手动创建
1 2 3 4
| mysql -uroot -proot_password -h10.96.0.2 CREATE DATABASE webstack; FLUSH PRIVILEGES;
|
一、配置文件(webstack.yml)
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
| --- apiVersion: v1 kind: ConfigMap metadata: name: mysql-cm namespace: dev data: my.cnf: | !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ [mysqld] server-id=001 log-bin=mysql-bin gtid_mode=on enforce_gtid_consistency=on relay-log=relay-log.log binlog_format=ROW master_info_repository=TABLE relay_log_info_repository=TABLE sync_master_info=1 slave_parallel_workers=2 binlog_checksum=CRC32 master_verify_checksum=1 slave_sql_verify_checksum=1 binlog_rows_query_log_events=1 slave_parallel_type=logical_clock general_log=1 log_output=FILE,TABLE
--- apiVersion: apps/v1 kind: StatefulSet metadata: name: mysql namespace: dev spec: selector: matchLabels: app: mysql serviceName: "mysql" replicas: 1 template: metadata: labels: app: mysql spec: terminationGracePeriodSeconds: 10 containers: - name: mysql image: registry.cn-hangzhou.aliyuncs.com/zznn/mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "root_password" - name: MYSQL_DATABASE value: webstack - name: MYSQL_USER value: webstack - name: MYSQL_PASSWORD value: "root_password" args: - --character-set-server=utf8mb4 volumeMounts: - mountPath: /var/lib/mysql name: mysql-storage - name: config-map mountPath: "/etc/mysql/my.cnf" subPath: my.cnf ports: - containerPort: 3306 name: mysql volumeMounts: - name: www mountPath: /var/lib/mysql volumes: - name: config-map configMap: name: mysql-cm volumeClaimTemplates: - metadata: name: www spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "managed-nfs-storage" resources: requests: storage: 2Gi
--- apiVersion: v1 kind: Service metadata: name: service-mysql namespace: dev spec: selector: app: mysql clusterIP: 10.96.0.2 type: ClusterIP ports: - port: 3306 targetPort: 3306
--- apiVersion: apps/v1 kind: Deployment metadata: name: webstack namespace: dev spec: replicas: 1 selector: matchLabels: app: webstack template: metadata: labels: app: webstack spec: terminationGracePeriodSeconds: 10 containers: - name: webstack image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:webstackv-1.2.2 env: - name: LOGIN_COPTCHA value: "false" - name: DB_HOST value: "10.96.0.2" - name: DB_DATABASE value: webstack - name: DB_USERNAME value: root - name: DB_PASSWORD value: root_password - name: APP_URL value: "" ports: - containerPort: 8000 name: webstack command: ['/entrypoint.sh','serve']
--- apiVersion: v1 kind: Service metadata: namespace: dev name: webstack-service spec: selector: app: webstack ports: - protocol: TCP port: 8000 targetPort: 8000 sessionAffinity: ClientIP type: NodePort
|
效果(验证mysql持久化)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| ll /mnt/data/mysql/dev-www-mysql-0-pvc-2396853f-5aed-4678-bfb7-73ca48e7a7cd/
drwxr-x--- 2 systemd-coredump systemd-coredump 4096 Nov 25 16:21 webstack/
|
验证: