Giter Site home page Giter Site logo

kubernetes-nginx-example's Introduction

Walk-through of a set of simple nginx configurations under Kubernetes. This is basically the same as the Kubernetes 101 and 201 examples.

Clone the example repo

git clone https://github.com/craig-willis/kubernetes-nginx-example.git

Start local Kubernetes cluster and download kubectl

If you don't have it already, run the provided shell script.

./kube-up-local.sh

Pod Example

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

Replication Controller Example

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 

Service Example

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 

NFS Example

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

kubernetes-nginx-example's People

Contributors

craig-willis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.