MySQL InnoDB Cluster on K3s and expose it to LAN by LoadBalancer
Takes from Official MySQL Operator documentation here
Install K3s and MetalLB here K3s with LoadBalancer MetalLB
Deploy MySQL Operator
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-crds.yaml
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-operator.yaml
Verify the deployment
kubectl get deployment mysql-operator --namespace mysql-operator
Create credentials secret
kubectl create secret generic mypwds \
--from-literal=rootUser=root \
--from-literal=rootHost=% \
--from-literal=rootPassword="123"
Deploy MySQL InnoDB Cluster
nano mycluster.yaml
apiVersion: mysql.oracle.com/v2
kind: InnoDBCluster
metadata:
name: mycluster
spec:
secretName: mypwds
tlsUseSelfSigned: true
instances: 3
router:
instances: 1
kubectl apply -f mycluster.yaml
kubectl get innodbcluster --watch
Expose MySQL InnoDB Cluster to LAN
Dont do this!!!
kubectl patch service mycluster -p '{"spec": {"type": "LoadBalancer"}}'
Next example deploy WordPress with MySQL InnoDB Cluster here
Connect Mysqlsh
kubectl run --rm -it myshell --image=container-registry.oracle.com/mysql/community-operator -- mysqlsh
Connect to specific pod in cluster
kunectl get pods
kubectl --namespace default exec -it mycluster-2 -- bash
mysqlsh root@localhost