Skip to content

A good first container to run on a new cluster. Plus a whole toolbox full of networking tools.

License

Notifications You must be signed in to change notification settings

etoews/hello-kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello Kubernetes

A simple web service to say hello to Docker, Kubernetes, or OpenShift using Python and Flask. It's a good first container to run on a new cluster.

This image is based on the excellent nicolaka/netshoot image, "a Docker + Kubernetes network troubleshooting swiss-army container". So if you need to do some network debugging you can run this container, open a shell in it, and have a whole toolbox full of networking tools at your fingertips.

These examples assume you're bringing your own Docker, Kubernetes, or OpenShift environment.

Local

Run locally

python -m venv venv
source venv/bin/activate
pip install --requirement requirements.txt

export FLASK_APP="app.py"
export FLASK_ENV="development"
export FLASK_RUN_HOST="0.0.0.0"
flask run

curl -s http://localhost:5000/

Docker

Build and run on Docker locally

docker build -t hello-kubernetes .
docker run -it --rm \
  --name hello \
  --publish 5000:5000 \
  hello-kubernetes

curl -s http://localhost:5000/

Run on Docker locally with image from DockerHub

docker run -it --rm \
  --name hello \
  --publish 5000:5000 \
  docker.io/etoews/hello-kubernetes:latest

curl -s http://localhost:5000/

Troubleshoot the container on Docker

docker exec -it hello bash

Kubernetes

Run on Kubernetes locally with image from DockerHub

kubectl create namespace world
kubectl apply -f manifests/kubernetes/deployment.yaml -n world
kubectl apply -f manifests/kubernetes/service.yaml -n world

watch kubectl get all -n world

curl -s http://localhost:5000/

kubectl delete namespace world

Notes:

  • Using this with Docker Desktop Kubernetes and type: LoadBalancer just works.

Run on Kubernetes remotely with image from DockerHub

kubectl create namespace world
kubectl apply -f manifests/kubernetes/deployment.yaml -n world
kubectl apply -f manifests/kubernetes/service.yaml -n world

watch kubectl get all -n world

hello_host=$(kubectl get service hello -o jsonpath="{.status.loadBalancer.ingress[*].hostname}" -n world)
curl -s http://${hello_host}:5000/

kubectl delete namespace world

Notes:

  • The kubectl delete namespace world will take a minute or two as it will also delete the load balancer instance behind it (e.g. delete the ELB if you're using EKS)

Troubleshoot the container and cluster networking on Kubernetes

See nicolaka/netshoot for the many networking tools included in the image.

hello_pod_0=$(kubectl get pods -o jsonpath="{.items[0].metadata.name}" -n world)
kubectl exec -it ${hello_pod_0} -n world bash
curl -s https://icanhazip.com

OpenShift

Run on OpenShift 4 remotely with image from DockerHub

oc new-project world

oc process -o yaml -f manifests/openshift4/deployment.yaml \
  --param IMAGE='docker.io/etoews/hello-kubernetes:latest' \
  | oc apply -f -
oc apply -f manifests/openshift4/service.yaml
oc apply -f manifests/openshift4/route.yaml

watch oc get all

hello_host=$(oc get route hello --no-headers -o=custom-columns=HOST:.spec.host)
curl http://${hello_host}/

oc delete project world

Build and run on OpenShift 4 remotely

oc new-project world

oc apply -f manifests/openshift4/imagestream.yaml
oc apply -f manifests/openshift4/buildconfig.yaml

oc start-build hello
watch oc get all

oc process -o yaml -f manifests/openshift4/deployment.yaml \
  --param IMAGE='image-registry.openshift-image-registry.svc:5000/world/hello:latest' \
  | oc apply -f -
oc apply -f manifests/openshift4/service.yaml
oc apply -f manifests/openshift4/route.yaml

watch oc get all

hello_host=$(oc get route hello --no-headers -o=custom-columns=HOST:.spec.host)
curl http://${hello_host}/

oc delete project world

Troubleshoot the container and cluster networking on OpenShift 4

See nicolaka/netshoot for the many networking tools included in the image.

hello_pod_0=$(oc get pods --selector app=hello -o jsonpath="{.items[0].metadata.name}")
oc rsh ${hello_pod_0}
curl -s https://icanhazip.com

Run a specific version

To run a specific version, use the hash from one of the commits as the tag.

For example.

docker run -it --rm \
  --name hello \
  --publish 5000:5000 \
  docker.io/etoews/hello-kubernetes:b262b385143f10242d5dbe201b999ded7782087a

curl -s http://localhost:5000/

About

A good first container to run on a new cluster. Plus a whole toolbox full of networking tools.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published