KEMBAR78
ProxySQL on Kubernetes | PDF
Kubernetes
Percona Live Online
May 19th, 2020
the Swiss Army Knife for your
ProxySQL Deployments
by Rene Cannao
Containers
Containers
Container Orchestrators
● Amazon Elastic Container Service (ECS)
● Azure Container Instance (ACI)
● Kubernetes (by Google)
● Nomad (by HashiCorp)
● Docker Swarm (Docker)
Container Orchestrator Capabilities
● Manage hundreds or thousands of containers
● Group hosts together
● Schedule where containers need to run based on available resources
● Enable communication between containers
● Associated containers to storage resources
● Group similar containers behind a load balancer
● Manage and optimize resources
● Ensure services are highly available and scalable
What is Kubernetes (k8s)
From https://kubernetes.io/ :
Kubernetes is an open-source system for automating deployment, scaling, and
management of containerized applications.
Hereafter referred to as k8s
Interesting Features
● Self-healing
● Service discovery and Load Balancing
● Automated Rollouts and Rollbacks
● Secret and configuration management
● Storage orchestration
Kubernetes Objects: Pods
Pod: The basic unit of deployment.
● Pods that run a single container
● Pods that run multiple containers that need to work together
Networking: each Pod is assigned a unique IP
Storage: a Pod can have a series of shared storage volumes
Pods and Networking
Network namespace: all containers in the same Pod can use localhost
IP-per-Pod: Each Pod is treated much like a VM i.e. assigned a unique IP.
Communication between Pods occurs as if they were VMs
Containers need to coordinate for ports assignment
Tools used in the demo
● minikube: a tool to run a single-node Kubernetes cluster inside a Virtual
Machine (VM)
● KVM/libvirt: hypervisor and toolkit to run the minikube Virtual Machine
● kubectl: the Kubernetes command-line tool, it allows you to run commands
against Kubernetes clusters
● Helm: the package manager for Kubernetes (define/install/upgrade/etc)
Installing Minikube
Details: https://kubernetes.io/docs/tasks/tools/install-minikube/
curl -Lo minikube
https://storage.googleapis.com/minikube/releases/latest/mini
kube-linux-amd64 
&& chmod +x minikube
sudo mv ./minikube /usr/local/bin/
Installing Helm
Details: https://helm.sh/docs/intro/install/
curl -fsSL -o get_helm.sh
https://raw.githubusercontent.com/helm/helm/master/scripts/g
et-helm-3
chmod 700 get_helm.sh
./get_helm.sh
Configuring minikube
minikube config set memory 6144
minikube config set cpus 3
minikube config set disk-size 50000MB
minikube config set vm-driver kvm2
minikube start
minikube status
Add dashboard
kubectl apply -f
https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
minikube addons enable dashboard
minikube dashboard --url
http://127.0.0.1:45536/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/pr
oxy/
# Start dashboard on local IP (forwarded from within Minikube VM) - default port is 8001
# and the address in this example 10.18.120.41 is the host physical machine IP (not the VM)
kubectl proxy --address=10.18.120.41 --accept-hosts='^.*'
Install MySQL using Helm
We are going to use Helm Chart to define, install, and upgrade application.
Add repo:
helm repo add bitnami https://charts.bitnami.com/bitnami
Install:
helm install mysql-8 -f ./mysql/values.yaml bitnami/mysql
MySQL cluster: deployment
NAME: mysql-8
LAST DEPLOYED: Tue May 19 13:45:30 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Please be patient while the chart is being deployed
Tip:
Watch the deployment status using the command: kubectl get pods -w --namespace default
Services:
echo Master: mysql-8.default.svc.cluster.local:3306
echo Slave: mysql-8-slave.default.svc.cluster.local:3306
MySQL cluster: how to connect
Administrator credentials:
echo Username: root
echo Password : $(kubectl get secret --namespace default mysql-8 -o
jsonpath="{.data.mysql-root-password}" | base64 --decode)
To connect to your database:
1. Run a pod that you can use as a client:
kubectl run mysql-8-client --rm --tty -i --restart='Never' --image
docker.io/bitnami/mysql:8.0.19-debian-10-r94 --namespace default --command -- bash
2. To connect to master service (read/write):
mysql -h mysql-8.default.svc.cluster.local -uroot -p my_database
3. To connect to slave service (read-only):
mysql -h mysql-8-slave.default.svc.cluster.local -uroot -p my_database
MySQL cluster: how to upgrade
To upgrade this helm chart:
1. Obtain the password as described on the 'Administrator credentials' section and
set the 'root.password' parameter as shown below:
ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-8 -o
jsonpath="{.data.mysql-root-password}" | base64 --decode)
helm upgrade mysql-8 bitnami/mysql --set root.password=$ROOT_PASSWORD

ProxySQL on Kubernetes

  • 1.
    Kubernetes Percona Live Online May19th, 2020 the Swiss Army Knife for your ProxySQL Deployments by Rene Cannao
  • 2.
  • 3.
  • 4.
    Container Orchestrators ● AmazonElastic Container Service (ECS) ● Azure Container Instance (ACI) ● Kubernetes (by Google) ● Nomad (by HashiCorp) ● Docker Swarm (Docker)
  • 5.
    Container Orchestrator Capabilities ●Manage hundreds or thousands of containers ● Group hosts together ● Schedule where containers need to run based on available resources ● Enable communication between containers ● Associated containers to storage resources ● Group similar containers behind a load balancer ● Manage and optimize resources ● Ensure services are highly available and scalable
  • 6.
    What is Kubernetes(k8s) From https://kubernetes.io/ : Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. Hereafter referred to as k8s
  • 7.
    Interesting Features ● Self-healing ●Service discovery and Load Balancing ● Automated Rollouts and Rollbacks ● Secret and configuration management ● Storage orchestration
  • 8.
    Kubernetes Objects: Pods Pod:The basic unit of deployment. ● Pods that run a single container ● Pods that run multiple containers that need to work together Networking: each Pod is assigned a unique IP Storage: a Pod can have a series of shared storage volumes
  • 9.
    Pods and Networking Networknamespace: all containers in the same Pod can use localhost IP-per-Pod: Each Pod is treated much like a VM i.e. assigned a unique IP. Communication between Pods occurs as if they were VMs Containers need to coordinate for ports assignment
  • 10.
    Tools used inthe demo ● minikube: a tool to run a single-node Kubernetes cluster inside a Virtual Machine (VM) ● KVM/libvirt: hypervisor and toolkit to run the minikube Virtual Machine ● kubectl: the Kubernetes command-line tool, it allows you to run commands against Kubernetes clusters ● Helm: the package manager for Kubernetes (define/install/upgrade/etc)
  • 11.
    Installing Minikube Details: https://kubernetes.io/docs/tasks/tools/install-minikube/ curl-Lo minikube https://storage.googleapis.com/minikube/releases/latest/mini kube-linux-amd64 && chmod +x minikube sudo mv ./minikube /usr/local/bin/
  • 12.
    Installing Helm Details: https://helm.sh/docs/intro/install/ curl-fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/g et-helm-3 chmod 700 get_helm.sh ./get_helm.sh
  • 13.
    Configuring minikube minikube configset memory 6144 minikube config set cpus 3 minikube config set disk-size 50000MB minikube config set vm-driver kvm2 minikube start minikube status
  • 14.
    Add dashboard kubectl apply-f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml minikube addons enable dashboard minikube dashboard --url http://127.0.0.1:45536/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/pr oxy/ # Start dashboard on local IP (forwarded from within Minikube VM) - default port is 8001 # and the address in this example 10.18.120.41 is the host physical machine IP (not the VM) kubectl proxy --address=10.18.120.41 --accept-hosts='^.*'
  • 15.
    Install MySQL usingHelm We are going to use Helm Chart to define, install, and upgrade application. Add repo: helm repo add bitnami https://charts.bitnami.com/bitnami Install: helm install mysql-8 -f ./mysql/values.yaml bitnami/mysql
  • 16.
    MySQL cluster: deployment NAME:mysql-8 LAST DEPLOYED: Tue May 19 13:45:30 2020 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: Please be patient while the chart is being deployed Tip: Watch the deployment status using the command: kubectl get pods -w --namespace default Services: echo Master: mysql-8.default.svc.cluster.local:3306 echo Slave: mysql-8-slave.default.svc.cluster.local:3306
  • 17.
    MySQL cluster: howto connect Administrator credentials: echo Username: root echo Password : $(kubectl get secret --namespace default mysql-8 -o jsonpath="{.data.mysql-root-password}" | base64 --decode) To connect to your database: 1. Run a pod that you can use as a client: kubectl run mysql-8-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.19-debian-10-r94 --namespace default --command -- bash 2. To connect to master service (read/write): mysql -h mysql-8.default.svc.cluster.local -uroot -p my_database 3. To connect to slave service (read-only): mysql -h mysql-8-slave.default.svc.cluster.local -uroot -p my_database
  • 18.
    MySQL cluster: howto upgrade To upgrade this helm chart: 1. Obtain the password as described on the 'Administrator credentials' section and set the 'root.password' parameter as shown below: ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-8 -o jsonpath="{.data.mysql-root-password}" | base64 --decode) helm upgrade mysql-8 bitnami/mysql --set root.password=$ROOT_PASSWORD