Skip to content

MySQL Redis

添加仓库

shell
helm repo add bitnami https://charts.bitnami.com/bitnami

查看chart

shell
helm show chart bitnami/mysql

查看默认值

shell
helm show values bitnami/mysql

install MySQL

shell
root@VM-0-13-ubuntu:/home/ubuntu# helm install mysql --set-string auth.rootPassword="1234" bitnami/mysql -n infra
NAME: my-mysql
LAST DEPLOYED: Mon Jan  6 15:33:58 2025
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 12.2.1
APP VERSION: 8.4.3

Did you know there are enterprise versions of the Bitnami catalog? For enhanced secure software supply chain features, unlimited pulls from Docker, LTS support, or application customization, see Bitnami Premium or Tanzu Application Catalog. See https://www.arrow.com/globalecs/na/vendors/bitnami for more information.

** 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 Primary: my-mysql.default.svc.cluster.local:3306

Execute the following to get the administrator credentials:

  echo Username: root
  MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-mysql -o jsonpath="{.data.mysql-root-password}" | base64 -d)

To connect to your database:

  1. Run a pod that you can use as a client:

      kubectl run my-mysql-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.4.3-debian-12-r5 --namespace default --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash

  2. To connect to primary service (read/write):

      mysql -h my-mysql.default.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"

WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs:
  - primary.resources
  - secondary.resources

test MySQL

进入 pod

shell
kubectl exec -it my-mysql-0 -- /bin/bash

test

shell
mysql -u root -p -h my-mysql.default.svc.cluster.local

Redis

查看默认值

shell
helm show values bitnami/redis
shell
helm upgrade --install redis bitnami/redis  --namespace db --set master.disableCommands="{'FLUSHALL'}" --set replica.replicaCount=1 --set auth.password="1234"

helm install redis-62 bitnami/redis --set replica.replicaCount=0 --set image.tag="6.2.14-debian-11-r2" -n db
shell
root@VM-0-13-ubuntu:/home/ubuntu# helm install redis bitnami/redis  --namespace infra
NAME: redis
LAST DEPLOYED: Mon Jan  6 15:39:20 2025
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 20.6.1
APP VERSION: 7.4.1

Did you know there are enterprise versions of the Bitnami catalog? For enhanced secure software supply chain features, unlimited pulls from Docker, LTS support, or application customization, see Bitnami Premium or Tanzu Application Catalog. See https://www.arrow.com/globalecs/na/vendors/bitnami for more information.

** Please be patient while the chart is being deployed **

Redis® can be accessed on the following DNS names from within your cluster:

    redis-master.default.svc.cluster.local for read/write operations (port 6379)
    redis-replicas.default.svc.cluster.local for read-only operations (port 6379)

To get your password run:

    export REDIS_PASSWORD=$(kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 -d)

To connect to your Redis® server:

1. Run a Redis® pod that you can use as a client:

   kubectl run --namespace default redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:7.4.1-debian-12-r3 --command -- sleep infinity

   Use the following command to attach to the pod:

   kubectl exec --tty -i redis-client \
   --namespace default -- bash

2. Connect using the Redis® CLI:
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-master
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-replicas

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace default svc/redis-master 6379:6379 &
    REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379

WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs:
- replica.resources
- master.resources

test redis

进入 pod

shell
kubectl exec -it redis-replicas-0 -- /bin/bash

主节点

shell
redis-replicas-0:/$ redis-cli -h redis-master.default.svc.cluster.local -p 6379
redis-master.default.svc.cluster.local:6379> auth am0yPlpJJM
OK
redis-master.default.svc.cluster.local:6379> set aa 123
OK
redis-master.default.svc.cluster.local:6379> get aa
"123"

从节点

shell
redis-replicas-0:/$ redis-cli -h redis-replicas.default.svc.cluster.local -p 6379
redis-replicas.default.svc.cluster.local:6379> auth am0yPlpJJM
OK
redis-replicas.default.svc.cluster.local:6379>  get aa
"123"
redis-replicas.default.svc.cluster.local:6379> set aaa 123
(error) READONLY You can't write against a read only replica.

文章来源于自己总结和网络转载,内容如有任何问题,请大佬斧正!联系我