diff --git a/mariadb/README.md b/mariadb/README.md index 64b356f..cf82f11 100644 --- a/mariadb/README.md +++ b/mariadb/README.md @@ -59,10 +59,52 @@ Docker Hub. ``` + ### Deploy with Kubernetes +This image can also be deployed on a Kubernetes cluster, such as [minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/).The following example YAML files are provided in the repository as reference for Kubernetes deployment: + +- [`mariadb-deployment.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/mariadb/mariadb-deployment.yaml): example using default configuration with secret to create a basic Mariadb service. + +- [`mariadb-deployment-conf.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/mariadb/mariadb-deployment-conf.yaml): example using your own custom configuration with secret to create a Mariadb service. + + + +Steps to deploy mariadb on a Kubernetes cluster: + +1. Create secret for Mariadb service. + + ``` + kubectl create secret generic mariadb \ + --from-literal=mysql-root-password= \ + --from-literal=mysql-user= \ + --from-literal=mysql-password= + ``` + +2. If you want to deploy `mariadb-deployment.yaml` + + ``` + kubectl create -f mariadb-deployment.yaml + ``` + + Or if you want to deploy `mariadb-deployment-conf.yaml` + + ``` + kubectl create -f mariadb-deployment-conf.yaml + ``` + +3. Install Mariadb bundle and connect to the service, where 30001 is the port number defined in your service. + + ``` + swupd bundle-add mariadb + mysql -h -u -p -P30001 + ``` + + + + ## Build and modify: The Dockerfiles for all Clear Linux* OS based container images are available at diff --git a/mariadb/mariadb-deployment-conf.yaml b/mariadb/mariadb-deployment-conf.yaml new file mode 100644 index 0000000..8b0f5c7 --- /dev/null +++ b/mariadb/mariadb-deployment-conf.yaml @@ -0,0 +1,100 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: mysql-config +data: + my.cnf: | + [mysqld] + + skip-log-bin + ssl=0 + + table_open_cache = 200000 + table_open_cache_instances=64 + back_log=3500 + max_connections=4000 + + innodb_file_per_table + + innodb_log_file_size=10G + innodb_log_files_in_group=2 + innodb_log_buffer_size=64M + + innodb_open_files=4000 + + innodb_buffer_pool_size= 100G + innodb_buffer_pool_instances=8 + + innodb_flush_log_at_trx_commit = 1 + innodb_doublewrite=1 + innodb_flush_method = O_DIRECT + innodb_file_per_table = 1 + innodb_io_capacity=2000 + innodb_io_capacity_max=4000 + innodb_flush_neighbors = 0 + innodb_use_native_aio=1 + + join_buffer_size=256K + sort_buffer_size=256K + +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: mariadb-deploy-secret + labels: + app: mariadb + type: database +spec: + replicas: 1 + template: + metadata: + labels: + app: mariadb + type: database + spec: + volumes: + - name: config-volume + configMap: + name: mysql-config + containers: + - name: mariadb + image: docker.io/clearlinux/mariadb + ports: + - containerPort: 3306 + name: db-port + args: ["--bind-address=0.0.0.0"] + volumeMounts: + - name: config-volume + mountPath: /usr/share/defaults/mariadb + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mariadb + key: mysql-root-password + - name: MYSQL_USER + valueFrom: + secretKeyRef: + name: mariadb + key: mysql-user + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: mariadb + key: mysql-password + +--- +apiVersion: v1 +kind: Service +metadata: + name: mariadb-svc +spec: + type: NodePort + ports: + - port: 3306 + targetPort: 3306 + nodePort: 30001 + selector: + app: mariadb + diff --git a/mariadb/mariadb-deployment.yaml b/mariadb/mariadb-deployment.yaml new file mode 100644 index 0000000..16a33ee --- /dev/null +++ b/mariadb/mariadb-deployment.yaml @@ -0,0 +1,53 @@ +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: mariadb-deploy-secret + labels: + app: mariadb + type: database +spec: + replicas: 1 + template: + metadata: + labels: + app: mariadb + type: database + spec: + containers: + - name: mariadb + image: docker.io/clearlinux/mariadb + ports: + - containerPort: 3306 + name: db-port + args: ["--bind-address=0.0.0.0"] + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mariadb + key: mysql-root-password + - name: MYSQL_USER + valueFrom: + secretKeyRef: + name: mariadb + key: mysql-user + - name: MYSQL_PASSWORD + valueFrom: + secretKeyRef: + name: mariadb + key: mysql-password + +--- +apiVersion: v1 +kind: Service +metadata: + name: mariadb-svc +spec: + type: NodePort + ports: + - port: 3306 + targetPort: 3306 + nodePort: 30001 + selector: + app: mariadb +