Bliv_Dev
Bliv_Dev

Reputation: 627

Execute MySQL Command in Kubernetes POD

does any one has an idea how to execute MySQL command inside Kubernetes POD from GitLab Runner ?

My Problem: I want to create two View Table for my Database that is setup and ready inside a GitLab Pipeline.

My current approach:

1 I read out the wordpress pod infos

MSPOD=$(kubectl get pods --namespace=default -o=jsonpath="{.items[*].metadata.name}" -l app=wordpress,tier=mysql)

2 I try to execute the create table view as single command as i can not sh into the POD via Runner.

kubectl exec $MSPOD -- mysql --database=wordpress --password='M*****?' -e "CREATE VIEW ...;"

But this does not work it actully tries to run the single items of the command in the Terminal. It also does not work as a embedded execution

kubectl exec $MSPOD -- $(mysql --database=wordpress --password='M*****?' -e "CREATE VIEW ...;")

Causing the same error.

Upvotes: 2

Views: 4907

Answers (1)

Janusz
Janusz

Reputation: 1481

The init container with MySQL client should work for you. Your SQL code can be provided as a configmap.

Upvotes: 3

Related Questions