Kubernetes: run persistent pods cassandra/mysql in Ubuntu servers - mysql

I'm newbie at kubernetes and I'm having problem to understand how I can run persistent pods (Cassandras ones or mysql ones) in ubuntu servers.
Correct me if I'm wrong, kubernetes can scale up or down the pods when it sees that we need more CPU but we are not talking about static code but data that are present in other nodes. So what will do the pod when it receive the request from the balancer? Also, kubernetes has the power to destroy nodes when it sees that the traffic has reduced, so how we can not lose data and not disturb the environment?

You should use volumes to map a directory in the container to persistent disks on the host or other storage

Related

OpenShift3 Persistent Volume Claims

Background:
I've deployed a spring boot app to the openshift platform, and would like to know how to handle persistent storage in OpenShift3.
I've subscribed to the free plan and have access to the console.
I can use oc command, but access seems limited under my user for commands like 'oc get pv' and others.
Question
How can I get a finer control over my pvc (persistent storage claim) on OS3?
Ideally, I want a shell and be able to 'list' file on that volume.
Thanks in advance for your help!
Solution
Add storage to your pod
use the command oc rsh <my-pod> to get access to the pod
cd /path-to-your-storage/
The oc get pv command can only be run by a cluster admin because it shows all the declared persistent volumes available in the cluster as a whole.
All you need to know is that in OpenShift Online starter, you have access to claim one persistent volume. The type of that persistent volume is ReadWriteOnce or RWO.
A persistent volume is not yours until you make a claim and so have a persistent volume claim (pvc) in your project. In order to be able to see what is in the persistent volume, it has to be mounted against a pod, or in other words, in use by an application. You can then get inside of the pod and use normal UNIX commands to look at what is inside the persistent volume.
For more details on persistent volumes, suggest perhaps reading chapter about storage in the free eBook at:
https://www.openshift.com/deploying-to-openshift/

Openshift scaling when using EBS

How does OpenShift scale when using EBS for persistent storage? How does OpenShift map users to EBS volumes? Because its infeasible to allocate 1 ebs volume to each user, how does openshift handle this in the backend using kubernetes?
EBS volumes can only be mounted on a single node in a cluster at a time. This means you cannot scale an application that uses one beyond 1 replica. Further, an application using an EBS volume cannot use 'Rolling' deployment strategy as that would require there to be 2 replicas when the new deployment is occurring. The deployment strategy therefore needs to be set to 'Recreate'.
Subject to those restrictions on your deployed application which has claimed a volume of type EBS, there is no problems with using EBS volumes as an underlying storage type. Kubernetes will quite happily map the volume into the pod for your application. If that pod dies and gets started on a different node, Kubernetes will then mount the volume in the pod on the new node instead, such that your storage follows the application.
If you give up a volume claim, its contents are wiped and it is returned to the pool of available volumes. A subsequent claim by you or a different user can then get that volume and it would be applied to the pod for the new application.
This is all handled and works no problems. It is a bit hard to understand what you are asking, but hopefully this gives you a better picture.

Is storage in Openshift Online free tier actually persistent?

I'm trying to migrate an Openshift v2 application to v3. I'm really struggling to understand the documentation. In the section on persistent volumes, it says the following:
EmptyDir has the same lifecycle as the pod:
EmptyDir volumes survive container crashes/restarts.
EmptyDir volumes are deleted when the pod is deleted.
I cannot understand what this means. I have added storage to my app using the Web Console, which allowed me to add 1 GB of persistent storage and give it to a particular mountpoint. I don't know if this is an "EmptyDir" volume or not (I think it isn't, but in that case why the warning in the persistent volumes section?). Now, every time I rebuild the application, a new pod is created (if I understand this correctly). So far my data has persisted when this happens. Does this warning mean it can suddenly be wiped out? Or is persistent storage persistent?
When you claim a persistent volume, you are not usually using an EmptyDir volume type, so that isn't relevant. EmptyDir is a special volume type that is managed a bit differently that would normally only be needed if you want to share some temporary file system space between different containers in the same pod.
In short, the persistent storage is indeed 'persistent'. You could see the difference by a simple experiment of creating a mysql with "non-persistent" vs "persistent".
The openshift architecture is built on Amazon infrastructure. Please check AWS EBS volume which is backbone of Openshift persistent storage -
https://aws.amazon.com/ebs/getting-started/
EDIT
Think it like that
EBS Volume -- ATTACHED TO --- pod ---- WHICH CONTAINS --- Containers
What document means to say that, if you destroy the POD (think of a machine), the EBS volume will be wiped out and available again as an unattached resource. Its lifecycle limited by pod. However, a POD can contain multiple containers (say JVM) and each container can share the EBS volume (think of a hard disk), but killing a container does not affect the EBS lifecycle.

run multiple mysql pods in kubernetes

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.

Google Compute Engine adding disk and SSL support

I am new to GCE. I was able to create new instance using gcutil tool and GCE console. There are few questions unclear to me and need help:
1) Does GCE provides persistent disk when a new instance is created? I think its 10GB by default, not sure though. What is the right way to stop the instance without loosing data saved on it and what will be the charge (US zone) if say I need 20GB of disk space for that?
2) If I need SSL to enable HTTPS, is there any extra step I should do? I think I will need to add firewall as per the gcutil addfirewall command and create certificate (or install it from third part) ?
1) Persistent disk is definitely the way to go if you want a root drive on which data retention is independent of the life cycle of any virtual machine. When you create a Compute Engine instance via the Google Cloud Console, the “Boot Source” pull-down menu presents the following options for your boot device:
New persistent disk from image
New persistent disk from snapshot
Existing persistent disk
Scratch disk from image (not recommended)
The default option is the first one ("New persistent disk from image"), which creates a new 10 GB PD, named after your instance name with a 'boot-' prefix. You could also separately create a persistent disk and then select the "Existing persistent disk" option (along with the name of your existing disk) to use an existing PD as a boot device. In that case, your PD needs to have been pre-loaded with an image.
Re: your question about cost of a 20 GB PD, here are the PD pricing details.
Read more about Compute Engine persistent disks.
2) You can serve SSL/HTTPS traffic from a GCE instance. As you noted, you'll need to configure a firewall to allow your incoming SSL traffic (typically port 443) and you'll need to configure https service on your web server and install your desired certificate(s).
Read more about Compute Engine networking and firewalls.
As alternative approach i would suggest deploying VMs using Bitnami. There are many stacks you can choose from. This will save you time when deploying the VM. I would suggest you go with the SSD disks, as the pricing is close between magnetic disks and SSDs, but the performance boost is huge.
As for serving the content over SSL, you need to figure out how will the requests be processed. You can use NGINX or Apache servers. In this case you would need to configure the virtual hosts for default ports - 80 for non-encrypted and 443 for SSL traffic.
The easiest way to serve SSL traffic from your VM is generate SSL certificates using the Letsencrypt service.