Building a sample Guestbook application using ksonnet on Kubernetes


You’ll need:

  • ksonnet
  • running Kubernetes cluster

e.g. `kubectl cluster-info`

kubectl get pods -n kube-system | grep kube-dns


Steps are:

1. create sandbox namespace

2. init app

3. create Guestbook UI component – Deployment and Service

4. create Datastore component



1. create a sandbox namespace

kubectl create namespace ks-dev

(More on Kubernetes: Namespaces )

and set it up with:

CURRENT_CONTEXT=$(kubectl config current-context)
CURRENT_CLUSTER=$(kubectl config get-contexts $CURRENT_CONTEXT | tail -1 | awk '{print $3}')
CURRENT_USER=$(kubectl config get-contexts $CURRENT_CONTEXT | tail -1 | awk '{print $4}')

kubectl config set-context ks-dev \
  --namespace ks-dev \
  --cluster $CURRENT_CLUSTER \
  --user $CURRENT_USER

which updates your $KUBECONFIG.

Why? To isolate from existing resources on your cluster. Now, we should see this context when you do:

kubectl config get-contexts

(which is just summarising what’s in your $KUBECONFIG. E.g. `cat $KUBECONFIG`)


2. init your app

ks init guestbook --context ks-dev

which creates a directory, guestbook, with all your manifests, etc.


3. create Guestbook UI component

First declare 2 Kubernetes API resources: a Deployment and a Service. More info: Kubernetes: Deployments and Services

Generate manifest for Guestbook UI:

ks generate deployed-service guestbook-ui \
  --image \
  --type ClusterIP

deployed-service: pattern for manifest (aka prototype)

guestbook-ui: filename and

--image: container image

--type ClusterIP: sets how Service is exposed (other options: NodePort or LoadBalancer)

Then, to view this app:

  # Set up an API proxy so that you can access the guestbook-ui service locally
  kubectl proxy > /dev/null &

  # Check out the guestbook app in your browser

A few gotchas:

1. i/o timeout

kubectl proxy > /dev/null
log.go:172] http: proxy error: dial tcp i/o timeout

is ‘cos you need to start your cluster. e.g. minikube start

2. bind: address already in use

kubectl proxy > /dev/null &

F1109 16:28:11.685303 72363 proxy.go:158] listen tcp bind: address already in use

is ‘cos kubectl proxy is already running. You can kill it with: `killall kubectl`

or just reload your URL.


4. create Datastore component

Available prototypes:

ks prototype list

Packages available:

ks pkg list


ks pkg install incubator/redis@master

and should now see it installed, plus the prototypes available. i.e. when you do:

ks prototype list

ks pkg list


See what parameters are required:

ks prototype describe redis-stateless

and generate:

ks generate redis-stateless redis



ks show default

and deploy:

ks apply default

(can use --dry-runto see summary)


Leave a Reply

Your email address will not be published. Required fields are marked *