“Hello World” on Kubernetes Cluster

Bhargav Shah
3 min readNov 8, 2019

--

Deploy a simple application on Kubernetes Cluster

This is a continuation of my last post on “Getting Started with Kubernetes (K8s)”, In this blog, we will be deploying the “Hello World” equivalent application on Kubernetes Cluster.

As we talked about in my previous blog there are overwhelming ways to get started with Kubernetes (K8s) cluster. For our demo, we will be using “Docker Desktop on Mac”. (follow the link and install it)

Let’s confirm installation working correctly,

  1. You should able to see the small “Moby” icon at top of your Mac.
  2. Make sure you have enabled “Kubernetes” — See those green dots before Docker and Kubernetes.

3. Lastly open, “Terminal” and check Command Line Interface is working correctly.

# Check Kubernetes and Docker CLI
$ kuberctl version
$ docker version

Now, Let’s get the required code for a demo application

$ git clone https://github.com/skynet86/hello-world-k8s.git
$ cd hello-world-k8s/

We have one file called “hello-world.yaml” which we are using to create our Kubernetes cluster.

Let me briefly explain the content of the file,

apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-deployment
labels:
app: hello-world
spec:
selector:
matchLabels:
app: hello-world
replicas: 2

A Deployment named “hello-world-deployment” is created, indicated by the “name” field.

The Deployment creates two replicated Pods, indicated by the “replicas” field.

The “selector” field defines how the Deployment finds which Pods to manage. In this case, we simply select a label that is defined in the Pod template (app: hello-world).

containers:
- name: hello-world
image: bhargavshah86/kube-test:v0.1
ports:
- containerPort: 80
resources:
limits:
memory: 256Mi
cpu: "250m"
requests:
memory: 128Mi
cpu: "80m"

An “image” field specifies which image used to run a container

limits and request field used to specify resources we are requesting and limiting to this particular container.

CPU unit “m” stands for “millicpu”. 1vCPU = 1000 millicpu.

Memory unit “Mi” stands for “mebibyte”.

apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30081
type: NodePort

Creating a service named “hello-world”. Using this service we are exposing our application at a node. The service type is specified by the “type” field. Ports are, Node 30081 -> Service 80 -> Pod/container 80. After deploying the application you can access the application from your local by browsing to http://localhost:30081.

$ kubectl create -f hello-world.yaml

Our application is running — Review it by hitting URL http://localhost:30081

http://localhost:30081

Did you know the difference between MiB and MB?

The megabyte is a multiple of the unit byte for digital information. Its recommended unit symbol is MB. The unit prefix mega is a multiplier of 1000000 (106) in the International System of Units (SI).[1] Therefore, one megabyte is one million bytes of information. This definition has been incorporated into the International System of Quantities.

The mebibyte is a multiple of the unit byte for digital information.[1] The binary prefix mebi means 220; therefore one mebibyte is equal to 1048576bytes, i.e., 1024 kibibytes. The unit symbol for the mebibyte is MiB.

Thank You.

--

--

Bhargav Shah
Bhargav Shah

Written by Bhargav Shah

Cloud Solution Architect at Walmart Japan

Responses (5)