I am trying to deploy a MySQL Docker Image to Kubernetes. I mostly managed all tasks, Docker Image up and running in Docker, one final thing is missing from Kubernetes deployment.
MySQL has one configuration which is stating which user can log on from which Host 'MYSQL_ROOT_HOST' to configure that for Docker is no problem, Docker Networking is using '172.17.0.1' for bridging.
The problem with Kubernetes, this must be the IP of the Pod trying to connect MySQL Pod and every time a Pod starts, this IP changes.
I try to put the Label of the Pod connecting to the MySQL Pod but it is still looking the IP of the Pod instead of DNS name.
Do you have an idea how I can overcome this problem, I can't even figure out how this should work if I set AutoScaling for the Pod that is trying to connect MySQL, replicas will all have a different IP.
Thx for answers....
As #RyanDowson and #siloko mentioned, you should use Service, Ingress or Helm Charts for these purposes.
Additional information you can find on Service, Ingress and Helm Charts pages.
Related
We have a MySQL server that is running on AWS using AWS RDS service and some Kubernetes pods which run some services that connect to this MySQL instance.
I have been using Intellij Idea (2020.1) to connect to these MySQL servers for quite some time. However, recently we have changed the policy to connect to these instances, and now it's only possible to connect to the MySQL servers from the Kubernetes pods. Hence, I now need to login to these pods and then query MySQL using the command-line MySQL-client.
Is there any way I can still use Intellij to connect to these MySQL instances than having to log in to the pods using something like SSH tunnelling or something like that?
Yes, setting up an SSH tunnel is recently straight forwards, but the setup depends on your VPC and EC2 configuration. There are a lot of how-tos on the net, e.g.: https://medium.com/#michalisantoniou6/connect-to-an-aws-rds-using-an-ssh-tunnel-22f3bd597924
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
I have an application that makes use docker-compose file to stand up on docker environment. Is there a way i can port/publish this multi-container application to IBM Bluemix?
The IBM Containers service has two distinct flavors you can use presently. You can either use Container Groups (backed by docker containers, the service also supports docker-compose files).
Your comment above seems to indicate that you want to create a docker container? You can do that from the service too. If you want to run docker machine, you will not be able to do that on the first service with container groups, or on the kubernetes service (currently. It is still in beta).
The new version of the service is container orchestration backed by Kubernetes, and managed by SoftLayer. You can use this in much the same way you use docker-compose, except your docker container cloud is managed by kubernetes rather than you, the user.
Sure! Try out this tutorial to get started:
https://console.ng.bluemix.net/docs/containers/container_single_ui.html#container_compose_intro
Im trying to connect to a postgres database, from a springboot application deployed in minishift.
The postgres server is running on the same host that minishift is running on.
I've tried setting the postgres serve to listen on a specific IP address, and use this same address in the springboot jdbc connection url but I still get org.postgresql.util.PSQLException: Connection to 172.99.0.1:5432 refused
I've also tried using 10.0.2.2
Also tried, in /etc/postgresql/9.5/main/postgresql.conf, setting:
listen_addresses = '*'
How can I connect to a database external to minishift, running on same host?
Besides the answer referenced in my comment, which suggests to make your database listen on the IP address of the Docker bridge, you could make your pod use the network stack of your host. This way you could reach Postgres on the loopback. This works only if can guarantee that the pod will always run on the same host as the database.
The Kubernetes documentation discourages using hostNetwork. If you understand the consequences you can enable it as in this example.
If a pod inside kubernetes can't see the IP address from the host then I guess its an underlying firewall or networking issue. Try opening a shell inside the pod...
kubectl exec -it mypodname bash
Then trying to ping, telnet, curl, wget or whatever to see if you can see the IP address.
It sounds like something's wrong with the networking setup of your minishift. It might be worth raising an issue with minishift: https://github.com/minishift/minishift/issues/new
If you can find an IP address on the host which is accessible from a docker pod you can create a Kubernetes Service and then an Endpoint for the service with the IP address of the database on your host; then you can use the usual DNS discovery of kubernetes services (i.e. using the service name as the DNS name) which will then resolve to the IP address. Over time you could have multiple IP addresses for failover etc.
See: https://kubernetes.io/docs/user-guide/services/#without-selectors
Then you can use Services to talk to all your actual network endpoints with your application code completely decoupled on if the endpoints are implemented inside kubernetes, outside with load balancing baked in!
I would like to create a kubernetes cluster to deploy mysql databases, like a mysql farm. These databases should be accessible from internet.
All databases on the same node will have the port 3306 listening, the kube-proxy or the DNS addon could redirect each request to an specific container?
I would like to create url's like myDB1.example.com:3306, myDB2.example.com:3306 that goes to an specific container.
I'm deploying this environment in AWS.
It's possible to create this cluster?
Yes. Starting point would be a (customized) MySQL Docker image with EBS backed volumes and you'd be using it in an Replication Controller to handle failover. On top of that you would have a Service that provides a stable and routable interface to the outside world. Optionally, put an AWS Elastic Load Balancer in front of it.