Execute MySQL Command in Kubernetes POD

10/13/2019

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.

-- Bliv_Dev
gitlab
kubernetes-pod
mysql

1 Answer

10/15/2019

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

-- Janusz
Source: StackOverflow