connecting jenkins hosted on kubernetes to MySQL on Google Cloud Platform

12/20/2018

I have hosted Jenkins on Kubernetes cluster which is hosted on Google Cloud Platform. I am trying a run a a python script though Jenkins. There is a need for the script to read a few values on MySQL. The MySQL instance is being run separately on one of the instances. I have been facing issues connecting Kubernetes to MySQL instance. I am getting the following error:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '35.199.154.36' (timed out)

This is the document I came across

According to the document, I tried connecting via Private IP address. Generated a secret which has MySQL username and password and included the Host IP address in the following format taking this document as reference:

apiVersion: v1
kind: Secret
metadata:
   name: db-credentials
type: Opaque
data:
  hostname:<MySQL external ip address>
  kubectl create secret generic literal-token --from-literal user=<username> --from-literal password=<password>

This is the raw yaml file for the pod that I am trying to insert in the Jenkins Pod template.

The image of the Kubernetes pod template as on Jenkins

Any help regarding how I can overcome this SQL connection problem would be appreciated.

-- Ranga Vittal
google-cloud-platform
jenkins
kubernetes
mysql

1 Answer

1/2/2019

You can't create a secret in the pod template field. You need to either create the secret before running the jobs and mount it from your pod template, or just refer to your user/password in your pod templates as environment variables, depending on your security levels

-- csanchez
Source: StackOverflow