Updated: Hello World in K8s using Nutanix Karbon

Getting started with Karbon and K8s in general can seem like a daunting task.  I wanted to create a simple “Hello World” website in K8s.  This is meant for people just starting to explore and play with K8s.  I am using Google and MetalLB to accomplish this.

Download *kubectl.cfg file from Karbon and export path for use with kubectl

export KUBECONFIG=/<path>/<kubectl-config.cfg>

Verify environment with kubectl get nodes

kubectl get nodes
NAME                                  STATUS   ROLES    AGE    VERSION
karbon-demo-devmin-87140a-k8s-master-0   Ready    master   178m   v1.13.4
karbon-demo-devmin-87140a-k8s-master-1   Ready    master   178m   v1.13.4
karbon-demo-devmin-87140a-k8s-worker-0   Ready    node     176m   v1.13.4
karbon-demo-devmin-87140a-k8s-worker-1   Ready    node     175m   v1.13.4
karbon-demo-devmin-87140a-k8s-worker-2   Ready    node     175m   v1.13.4

Create the Google “hello-app” in Karbon.  This is from the Google quick-start guide here.

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0

After the app is deployed you need to create a service using “kubectl expose deployment” to allow external traffic

kubectl expose deployment hello-server --type LoadBalancer \
  --port 80 --target-port 8080

Optional, but recommend would be to add the MetalLB load-balancer here

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml

kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"

Apply a layer 2 config that has your IP range.  We will download and edit the example form MetalLB.  In this example we are using 10.1.2.220-10.1.2.225

wget https://raw.githubusercontent.com/google/metallb/v0.9.3/manifests/example-layer2-config.yaml

vi example-layer2-config.yaml

Now apply the L2 configuration

kubectl apply -f example-layer2-config.yaml

The previous “hello-app” will now get an external IP from MetalLB

kubectl get service hello-server 
NAME           TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)        AGE
hello-server   LoadBalancer   172.19.20.179   10.1.2.220   80:31703/TCP   3h17m

You can now open a browser to your EXTERNAL-IP and verify the Google “hello-app” is responding

You May Also Like

About the Author: devmin

systems architect with interest in automation, k8s, linux, devops, bash, real estate, anonymity