PlanetScale provides a Vitess operator, as well as several examples to use in a Kubernetes environment. In this article, we'll take a look at a simple example of running a Vitess Kubernetes cluster locally on an EC2 instance. For this example, you'll want an EC2 instance with more resources than the c5.xlarge
instance type used in the previous lessons. Go ahead and spin up a c5.2xlarge
or bigger, and get Vitess downloaded and installed before proceeding.
Navigate to the operator
directory:
cd ~/dev/vitess/examples/operator
To run with Kubernetes, you will need container software installed. For this, we'll use Docker. To install:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world
Next, install Kubernetes:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
For this example, we'll run the entire Kubernetes cluster locally. We'll need to install Minikube for this. To install and start Minikube:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
sudo usermod -aG docker ubuntu
sudo su - ubuntu
minikube start --kubernetes-version=v1.28.5 --cpus=4 --memory=8000 --disk-size=10g
Next, it's time to start up the operator and a simple example Vitess cluster:
kubectl apply -f operator.yaml
kubectl apply -f 101_initial_cluster.yaml
It may take several seconds or minutes for the cluster to come fully online. As it starts up, you can monitor the status of the Pods and Services using:
When everything shows that is is Running
successfully, you should be good to go.
To connect to the cluster, first set up the appropriate port forwarding and aliases.
./pf.sh &
alias vtctldclient="vtctldclient --server=localhost:15999"
alias mysql="mysql -h 127.0.0.1 -P 15306 -u user"
Then you can connect to the database simply by typing:
If you'd like to load a schema into the database, try running:
vtctldclient ApplySchema --sql-file="create_commerce_schema.sql" commerce vtctldclient ApplyVSchema --vschema-file="vschema_commerce_initial.json" commerce