简体   繁体   中英

Create Kubernetes Pod with MySQL and PHP?

Hi there, I have a docker container that is a php backend. I have created a kubernetes pod of this container. This is what my yml file looks like:

 apiVersion: v1
 kind: Pod
 metadata:
  name: backend
  spec:
  containers:
 - name: backend
  image: 000.dkr.ecr.eu-west-1.amazonaws.com/fullstackapp
  ports:
  - containerPort: 8000

However I want to be able to connect my MySql database (which is also a docker container) to the backend in the same pod. However I have no idea how to go about doing this. Any help would be appreciated!

Well,

Since you have dockerized your app (you made an docker image), you also must use a docker image for your MySql database.

But here is the kicker, you need also to create services for your app pod and your MySql pod.

You can find all the details in the k8 documentation (which is really good)

To make myself clear:

1.) First create a deployment object for your app.

2.) Then make a service for your app.

You rinse and repeat for the MySql database.

1.) You need the deployment object (and not the pod kind), because the deployment object keeps you pod alive when one breaks, for instance if you have tree replicas (pods) the replicaSet that the deployment object uses, will make sure that there are three replicas of your app.

2.) Services will group your pods (via labels ), because the pods that the deployment object will generate will have a short life ( ephemeral ), meaning their IP address will be unstable and you wont be able to rely on them.

So, you will use services that will give you a cluster IP ( virtual IP ), that other objects can use. For instance; when your app wants to connect to the MySQL database.

You can use the name of the MySQL service in your apps configuration files.

So, basically that's how you would connect a MySQL pod to you apps pod .

Take a look at the katacode project, they give you a playground to learn this kind of stuff.

Tom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM