Home

Awesome

logo

Modified Guestbook k8s Example

Guestbook k8s example is meant to showcase how k14s tools work together with a realistic application.

This example is based on guestbook example from kubernetes/examples. Changes were done to remove unused functionality.

Install k14s Tools

Head over to k14s.io for installation instructions.

Deploy

git clone https://github.com/k14s/k8s-guestbook-example
cd k8s-guestbook-example/

Using k14s tools, deploy via:

kapp deploy -a guestbook -f <(ytt -f config/ | kbld -f-) --diff-changes

Above command does the following:

If you are using Minikube as your deployment target, run eval $(minikube docker-env) beforehand so that kbld can successfully shell out to Docker CLI. By default images are kept locally (not pushed).

If you are using remote cluster as your deployment target you will have to provide registry destination where images could be pushed and be accessible to the cluster. You will still need to have access to Docker CLI and be logged in so that pushes are successful.

docker login ...
kapp deploy -a guestbook -f <(ytt -f config/ --data-value push_images=true --data-value push_images_repo=docker.io/dkalinin | kbld -f-) -c

(Even if you are deploying to remote cluster, Minikube could be used for its Docker daemon; just make sure that your ~/.kube/config points to your remote cluster.)

Deploying to Online Playground

If you want to use online playground instead of your own cluster, head over to Katacoda Kubernetes Playground. You will have to set --data-value katacoda=true flag when using ytt and untaint master node, before proceeding with the above command. See comments in config/katacoda.yml for additional details.

kubectl taint nodes master node-role.kubernetes.io/master-

(Command does end with a hyphen.)

Viewing Frontend App

Once deployed successfully, you can access frontend service at 127.0.0.1:8080 in your browser via kubectl port-forward command:

kubectl port-forward svc/frontend 8080:80

You will have to restart port forward command after making changes as pods are recreated. Alternatively consider using k14s' kwt tool which exposes cluser IP subnets and cluster DNS to your machine and does not require any restarts:

sudo -E kwt net start

and open http://frontend.default.svc.cluster.local/.

Making Changes

Once deployed, feel free to make changes to the app, and re-run same command.

For example, change frontend/guestbook.php:

-$bg = getenv('GUESTBOOK_BG');
+$bg = 'yellow';

or change frontend/frontend.yml:

-  GUESTBOOK_BG: "#eee"
+  GUESTBOOK_BG: "yellow"

and run exactly same command as before:

kapp deploy -a guestbook -f <(ytt -f config/ ...any opts... | kbld -f -) --diff-changes

Note that during second deploy each tool will try to be as optimal as possible based on changes made:

Directory Layout

Highlighted Features

Here are some features of k14s tools as used in this example:

ytt

kbld

kapp

Join the Community and Make Carvel Better

Carvel is better because of our contributors and maintainers. It is because of you that we can bring great software to the community. Please join us during our online community meetings. Details can be found on our Carvel website.

You can chat with us on Kubernetes Slack in the #carvel channel and follow us on Twitter at @carvel_dev.

Check out which organizations are using and contributing to Carvel: Adopter's list