Setup
Get Dockers
- Download and install Dockers
Get and compile Kubernetes
- git clone https://github.com/kubernetes/kubernetes.git
- cd kubernetes
- make
Start up the cluster
sudo hack/local-up-cluster.sh
Start a new terminal and get this tutorial
- git clone https://github.com/randcode-generator/kubernetes_tutorial_1.git
- cd kubernetes_tutorial_1
- git submodule init
- git submodule update
Build a new docker image for the negative number generator project
cd neg-num-generator sudo docker build -t neg-num-gen:v1 .
Build a new docker image for the positive number generator project
cd ../pos-num-generator sudo docker build -t pos-num-gen:v1 .
Run the following commands to create pods
kubectl create -f pos-num-pod.yaml kubectl create -f neg-num-pod.yaml
Run the following commands to create services
kubectl create -f num-service.yaml
How to use
Get a list of services
kubectl get service
Look for the cluster ip and port for the service named num-service.
Open http://<cluster ip>:<port>
For example:
http://10.0.0.39:8082
You will a positive number. If you refresh, you will get another positive random number
To get negative numbers,
kubectl edit service num-service
Find the field called component. Change the pos-num to neg-num. Save and quit.
Restart your browser and open up http://<cluster ip>:<port>, you should see random negative numbers