Deploying your app to your Kubernetes cluster
Now that you have a cluster, you may want to deploy your app to it...
As you may have noticed, the app directory which you created on your local machine earlier (see Running your app locally section) contains a
kubernetes/ directory - This contains all the Kubernetes (K8s) definition files which the Kubernetes client (
kubectl) needs to deploy and orchestrate your app inside your K8s cluster. You can modify and add files as you like but do not remove (and be careful when editing) the
app-src-container container inside
socketcluster-deployment.yaml - This is the container which holds your app's source code in production so avoid messing with those lines.
Note that the
baasil deploy command uses
docker commands behind the scenes to deploy your app to your cluster.
Before you deploy your app though, you need to setup your
kube config file.
First, navigate to your Rancher control panel - Click on the
Rancher link from the Baasil.io dashboard https://baasil.io/#!/dashboard
You will need to authenticate yourself with GitHub in order to access the Rancher control panel.
Once you have access to your Rancher control panel, in the top navigation bar, open the
Kubernetes dropdown menu and click on
On this screen, click on the
Generate Config button then click on the
Copy to Clipboard button.
Then, you just need to paste this config inside your
kube config file (which is at path
~/.kube/config on Linux) - If the file doesn't already exist, you should create it (you might need to create the
~/.kube/ directory first).
Before you deploy, it should be noted that some corporate proxies and mobile 3G network providers block plain (non-encrypted) WebSocket traffic; because of this, we configured the SocketCluster container to require TLS credentials by default (See
kubernetes/sc-ingress.yaml for Kubernetes config).
You can get your TLS private key and public certificate however you like, but for simplicity, we recommend that you generate a self-signed key/cert pair (note that you will get a warning in the browser but this is fine for testing). You can generate your key and certificate using a single command: https://major.io/2007/08/02/generate-self-signed-certificate-and-key-in-one-line/
Once you have your private key and public certificate, you just need to go to your Rancher control panel, open the
Infrastructure downdown menu, click on
Certificates then click on the
Add Certificate button.
You should set the
scc-tls-credentials and then you just need to copy-paste the content of your key file into the
Private Key field and copy-paste the content of your cert file into the
Certificate field. If you are using a self-signed key/cert pair, you can leave the CA text field empty.
Ok, that's it, you are now ready to deploy your app to your cluster.
On your local machine, whilst inside your app directory, just run:
It should prompt you for some details. If you make any mistakes, you can edit the
baasil.json file manually or delete it and try deploying again.
Once the deployment is done, you can access your app from your ingress' IP address
https://<my-ingress-ip-address>. You can get this address from your Rancher control panel by opening the
Kubernetes > Infrastructure Stacks screen and under
kubernetes-ingress-lbs, click on
default-rancherlb-scc-ingress, then click on the
Ports tab - The external IP address for your app/service should show up next to port 443.
Note that the
baasil deploy command should be used for initial deploys (if the app is not already running in your cluster).
To perform subsequent 'live' deployments, you should use this command instead: