Score:0

Should I add a "MySQL_URI" to the MySQL Kubernetes deployment file?

pl flag

This is a Kubernetes deployment file that originally was using only MongoDB database. I tried to add MySQL to it as well like below:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
    spec:
      containers:
        - name: auth
          image: learner/auth
          env:
            - name: MONGO_URI
              value: 'mongodb://auth-mongo-srv:27017/auth'
            - name: JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: jwt-secret
                  key: JWT_KEY
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: MYSQL_KEY
---
apiVersion: v1
kind: Service
metadata:
  name: auth-srv
spec:
  selector:
    app: auth
  ports:
    - name: auth
      protocol: TCP
      port: 3000
      targetPort: 3000

But I am not sure if I must also define another env for MYSQL_URI or not? Something like:

    - name: MYSQL_URI
      value: 'mysql://auth-mongo-srv:3306/auth'
Score:0
qa flag

It is not required to create a separate env variable for MYSQL_URI in the yaml files while encrypting the username and password for your mysql database. However, when you are referring to this DB in your application code you need to use the MYSQL_URI and this encrypted data for connecting to Mysql DB.

Please go through this link for yaml file reference.

best_of_man avatar
pl flag
I have exactly done what it says in the suggested link, but when I try `mysql -p` and enter the password, I get `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)` error!
best_of_man avatar
pl flag
Please look at my original question here: https://serverfault.com/questions/1118742/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run
Kranthiveer Dontineni avatar
qa flag
@best_of_man I have gone through your original question. Since you are deploying your mysql inside a container or pod and trying to connect to it using another container or pod, you should be using the private IPs or cluster IPs of the pods. I have seen that in your mysql.cnf file IP is localhost but it should be the private IP of your mysql pod. This kubernetes official documentation (https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/#deploy-mysql) helps you configuring your mysql deployment.
best_of_man avatar
pl flag
Sorry but within my original question, I was just trying to run the mysql inside the deployed pod not from inside another pod. I think maybe I should change the `mysql` settings inside the deployed pod, not inside my `mysql` local files! But I don't know how to open the `/etc/my.cnf` file inside the pod because `nano` or `vim` aren't installed and `apt` command doesn't work to install something inside the pod!
Kranthiveer Dontineni avatar
qa flag
@best_of_man since you didn't used that mysql instance and if there is no data available in it, you can go with new deployment using the steps which I have provided above. Meanwhile, I will try to figure out a way to help you correcting your existing /etc/my.cnf file. I think we can do something by using kubectl exec command like moving the existing my.cnf to my.cnf.bkp and creating a new file using the shell script.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.