Skip to main content

Basic deployment MySQL on Kubernetes microK8s

Create deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
spec:
replicas: 3
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:latest
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
type: LoadBalancer

Try to connect to MySQL

mysql -u root -p -h 10.11.0.51 -P 3306

Some of information about the deployment

microk8s kubectl get pods --watch
microk8s kubectl get pods -o wide
microk8s kubectl logs mysql-deployment-c4fccb7d9-fr5tw
microk8s kubectl describe services mysql-service