Walk-through of a set of simple nginx configurations under Kubernetes. This is basically the same as the Kubernetes 101 and 201 examples.
git clone https://github.com/craig-willis/kubernetes-nginx-example.git
If you don't have it already, run the provided shell script.
./kube-up-local.sh
This example starts pod with a single nginx container:
kubectl create -f nginx-pod.yaml
kubectl get pods
NAME READY STATUS RESTARTS AGE
k8s-master-127.0.0.1 3/3 Running 0 48m
nginx 0/1 Running 0 8s
You can access the running container using curl:
curl http://$(kubectl get pod nginx -o go-template={{.status.podIP}})
Delete this pod, since we'll create a replication container next:
kubectl delete pod nginx
This example creates a replication controller that manages two nginx containers.
kubectl create -f nginx-rc.yaml
List the replication controller using kubectl:
kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
nginx-controller nginx nginx app=nginx 2 2m
List the pods/containers using kubectl:
kubectl get pods
NAME READY STATUS RESTARTS AGE
k8s-master-127.0.0.1 3/3 Running 0 1h
nginx-controller-lu0ov 0/1 ContainerCreating 0 2s
nginx-controller-rvpru 0/1 ContainerCreating 0 2s
You can again access each nginx container via it's assigned IP:
curl http://$(kubectl get pod <pod name> -o go-template={{.status.podIP}})
While you can delete the replication controller (which will delete the running pods/containers), don't do it now since we need the replication controller running for the service.
kubectl delete rc nginx-controller
This example assumes that you have a running replication controller, as above.
kubectl create -f nginx-service.yaml
List the services using kubectl:
kubectl get services
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
kubernetes 10.0.0.1 <none> 443/TCP <none> 53m
nginx-service 10.0.0.245 <none> 8000/TCP app=nginx 1m
List the pods using kubectl:
kubectl get pods
NAME READY STATUS RESTARTS AGE
k8s-master-127.0.0.1 3/3 Running 0 1h
nginx-controller-lu0ov 1/1 Running 0 7m
nginx-controller-rvpru 1/1 Running 0 7m
Now you can access the service endpoint using curl:
export SERVICE_IP=$(kubectl get service nginx-service -o go-template={{.spec.clusterIP}})
export SERVICE_PORT=$(kubectl get service nginx-service -o go-template'={{(index .spec.ports 0).port}}')
curl http://${SERVICE_IP}:${SERVICE_PORT}
Deleting the service only deletes the service, not the replication controller:
kubectl delete service nginx-service
Create sample export filesystem and data:
mkdir /data
echo "Test" >> /data/index.html
chmod a+r /data
chmod a+r /data/index.html
Export the filesystem via nfs:
sudo vi /etc/exports
/data *
sudo servicectl start nfsd
Set the IP address of the docker0 interface in nfs-pv.yaml. Create the volumes and nginx pods:
kubectl create -f nfs-pv.yml
kubectl create -f nfs-pvc.yml
kubectl create -f nginx-pod-nfs.yml
Test your nginx:
curl `kubectl get pod nginx-nfs -o go-template="{{.status.podIP}}"`
Test