/kubernetes-fundamentals

Example applications you can run on a Kubernetes cluster, such as Minikube.

Primary LanguageShell

Discovering Clusters With Minikube

Example containers one can run on a Kubernetes cluster, such as Minikube.

Demonstrating Kubernetes

Kubernetes setup

  1. Clone this Git project
  2. Install Minikube (or any other Kubernetes cluster)
  3. Install kubectl command line tool for Kubernetes
  4. Start Minikube: minikube start --kubernetes-version v1.10.0 --cpus 4 --memory 8000 --disk-size 80g --bootstrapper localkube --profile fundamentals
  5. Use profile specificed above: minikube profile fundamentals
  6. Verify minikube status && kubectl version reports correctly

Exercise 1: Run a POD and load balance

kubectl run hello --image=gcr.io/google_containers/echoserver:1.7 --port=8080 kubectl expose deployment hello --type=NodePort curl -s $(minikube service hello --url) curl -s $(minikube service hello --url) | grep Hostname while true; do sleep 1; curl -s $(minikube service hello --url) | grep Hostname; done Split to new command line kubectl scale deployment hello --replicas=3 kubectl delete pod hello-[some pod id]

Exercise 2: Run a R Server

Run the R/deploy.sh script that uses KubeCtl to stand up the application containing R Shiny engine and its dashboard.

Exercise 3: Run a RabbitMQ cluster

Initialize the Helm package manager and install the Helm chart for RabbitMQ.

helm init && helm update
helm install --name rabbit --namespace rabbit --set rbacEnabled=false --set rabbitmq.username=admin --set rabbitmq.password=admin --set serviceType=NodePort --set rabbitmq.nodePort=31333 --set replicas=3 stable/rabbitmq

Exercise 4: Intra-service communication

An immediate benefit Kubernetes provides developers of containers is a level playing field for communicating between containers. Each container runs in a Pod, each Pod is fronted by a Service that routes traffic to its associated Pods, round-robin style. While each Pod in Kubernetes' network plane is assigned a virtual IP, you should not to connect to containers with these IPs. In fact, within your container code there should typically be no coupling to the Kubernetes ecosystem.

Simply, communication is easily achieved with the Kube-DNS or CoreDNS service, standard issue for most Kubernetes clusters. With this, as long as you know the label assigned to the service you can reach it with a simple URL such as http://label-of-service/namespace/local.srv.local. Even simpler, if the two Pods are in the same Namespace you can simple use this short URL http://label-of-service. The :[port] postfix can also be specified. Try this 3 step example.

  1. Add a Nginx deployment with an associated service named "nginx" to the default namespace:
kubectl create -f https://raw.githubusercontent.com/javajon/kubernetes-fundamentals/master/nginx/nginx.yaml
  1. Start and enter a (Busybox container](https://docs.docker.com/samples/library/busybox/) in a separate Pod in the same Namespace.
kubectl run curl-test --image=radial/busyboxplus:curl -i --tty --rm
  1. Shortly your terminal will assume the prompt inside the Busybox container. Enter:
curl http://nginx
curl -I http://nginx:80
curl http://nginx/default
curl http://nginx/default/svc/cluster/local

These variants will all access the same Nginx default web page. As long as your know the service the Kubernetes DNS will resolve your URL to the Service name that fronts the target's Pod(s).

More on this can be found here.

Technology stack

  • Kubernetes
  • Minikube
  • KubeCtl
  • Helm
  • Nginx
  • Busybox
  • R Shiny Server
  • RabbitMQ
  • KubeDNS
  • On Windows consider the Git Bash command prompt to run Bash scripts.

Additional information