Continuing on from Part One where we went through a brief history of containers and Kubernetes then Dockerized a NodeJS application, now we are ready to deploy to Kubernetes. If this is your first or nth time deploying to Kubernetes, Shipa makes this simple. You don’t have to worry about authoring multiple Kubernetes manifests and templates to deploy your application, all you need is an image. Fire up your favorite Kubernetes cluster, sign up for Shipa Cloud for free, and let’s deploy to it.
Getting a Kubernetes Cluster
There are lots of ways to get a Kubernetes cluster today. From locally on your machine with minikube or K3d to Kubernetes cloud vendors such as Civo all the way to the large scale cloud vendors such as Amazon AWS. Shipa has the ability to bind to a multitude of Kubernetes clusters. Though if this is your first time using Kubernetes and don’t want to get into some of the networking concepts e.g exposing from your local machine or navigating through a large public cloud vendor, Civo’s solution is purpose-built for Kubernetes.
Shipa is actually in the Civo Marketplace, though this is to install your own version of Shipa on your own infrastructure. Simply sign up for a Shipa Cloud account and spin up a Civo Kubernetes cluster.
Install Kubectl
The first item you need is to grab kubectl, which is the command-line interface for Kubernetes. The easiest way to install it is with Homebrew.
brew install kubernetes-cli
Spin Up a Civo Cluster
Once you get kubectl installed, sign up for Civo Cloud and spin up your first Kubernetes cluster.
Civo -> Kubernetes -> +Create new cluster
Name: myjscluster
Network: Default
Firewall: Ensure that the cluster is publicly accessible with ports 80/443/6443.
Instances: one
Size: Large
Under Step 7, remove the default installation of Traefik in the Management Tab by clicking to un-select the card.
With Traefik de-selected, click on Create, within a few moments you will have a functioning Kubernetes cluster.
With the up and running Civo Kubernetes cluster, you can now wire the Kubeconfig context to your local machine.
Wiring Your Kubeconfig
Kubeconfig is a configuration file that tells kubectl how to access your Kubernetes cluster. Civo provides a CLI that you can download and inject Kubeconfigs on your local machine. Install and authenticate the CIVO CLI, then pull down your cluster’s Kubeconfig.
brew tap civo/tools brew install civo civo apikey add <Api-Key-Name> <your-API-key> civo kubernetes config myjscluster --save kubectl config use-context myjscluster
With kubectl wired up, run “kubectl get nodes” to validate you are connected.
Now you are ready to connect your new Kubernetes cluster to Shipa.
Wiring your Kubernetes Cluster to Shipa
When you log into Shipa Cloud for the first time, the first action to do is to create a Shipa Framework e.g the “how”. Frameworks are homes to your abstractions and policies, creating one with defaults is the quickest route to deployment.
First Shipa Framework Creation
Click on Frameworks then + Add Framework. Select “Deploy applications with reasonable defaults” and click next.
Next, fill out the General Configuration.
Name: jsframework
Plan: shipa-plan
Teams: shipa-team
Then click Create. You know have a Framework to deploy against. The next step is to bind your Kubernetes cluster to Shipa so Shipa can deploy on your behalf.
Binding a Cluster to Shipa Cloud
Binding a cluster e.g the “where” has a few parts that are needed. You will need to get the Kubernetes Endpoint [e.g Kubernetes API], a Role Binding, and a Certificate. Here is how to get all three.
Click on Clusters -> + Add Cluster
Name: civocluster
Frameworks: jsframework
Click Next and now it is time to fill in the connection details.
Kubernetes API Endpoint
Run this command to get the Kubernetes API Endpoint.
kubectl cluster-info | grep 'Kubernetes' | awk '/http/ {print $NF}'
Token
Shipa will need a Service Account to act on your behalf on the cluster. You can grab the shipa-admin-service-account.yaml in the documentation and then apply the account. Create a file called “shipa-admin-service-account.yaml” and save the file.
Next, apply this Kubernetes manifest.
kubectl apply -f shipa-admin-service-account.yaml
Now can grab the token associated with the role.
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep shipa-admin | awk '{print $1}')
Certificate
Lastly, you will need a Certificate for the connection.
kubectl get secret $(kubectl get secret | grep default-token | awk '{print $1}') -o jsonpath='{.data.ca.crt}' | base64 --decode
With those three pieces, add them to the UI.
Click Next and then you can use the Shipa Default Ingress Controller e.g just click Create.
In about a minute, your cluster will be available to Shipa.
Now you are ready to make a Shipa Application and deploy it to Kubernetes.
Your First Kubernetes Deployment
The final piece so you can deploy is a Shipa Application e.g the “what” you will deploy.
Shipa -> Applications -> + Add Application
Name: jsforkubernetes
Framework: jsframework
Team: shipa-team
Click Create and now you can deploy through this Application.
Click on the Name of the application e.g “jsforkubernetes” then the deployment icon.
All you need now is the image to deploy. To get this information the Docker image:tag combo, can navigate back to your Docker Hub repository if you leveraged Part One of this example to grab those details.
In this case, the image I created in Part One is located at: docker.io/rlachhman/samplejs:1.0.0
Click Deploy. Once the status of the Application moves from “idle” to “running” click on the Endpoint that was created by Shipa to see your hard work.
Click on the Endpoint and you are all set.
With that, you have gone from JS to K8s. With Shipa, there is certainly a lot of the art of the possible. The duality of Shipa with the aim to make Kubernetes an afterthought and the policy enforcement aspect [not touched in this tutorial series] certainly helps move Developer Experience [DX] and engineering efficiency forward.
Cheers,
-Ravi