原文:https://kubernetes.io/zh/docs/tasks/run-application/run-replicated-stateful-application/
docker pull mysql:5.7
docker pull gcr.io/google-samples/xtrabackup:1.0
kubectl apply -f mysql.yaml
kubectl get pods -w
# 缩容
kubectl scale statefulset mysql --replicas=2
# 扩容
kubectl scale statefulset mysql --replicas=3
创建数据库:
# 直连写入
kubectl run mysql-client --image=mysql:5.7 -i --rm --restart=Never --\
mysql -h mysql-0.mysql <<EOF
CREATE DATABASE test;
CREATE TABLE test.messages (message VARCHAR(250));
INSERT INTO test.messages VALUES ('hello');
EOF
查询:
# 通过 service 负载均衡查询
kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\
mysql -h mysql-read -e "SELECT * FROM test.messages"
# 直连查询
kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\
mysql -h mysql-0.mysql -e "SELECT * FROM test.messages"
# 直连查询
kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\
mysql -h mysql-0.mysql -e "SELECT * FROM test.messages"
# 直连查询
kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\
mysql -h mysql-0.mysql -e "SELECT * FROM test.messages"
kubectl delete -f .