Code Monkey home page Code Monkey logo

kubernetes-nginx-multisite-example's Introduction

Kubernetes NGINX multisite cluster

An NGINX instance used as a reverse proxy dispatch traffic to the corresponding Pod via service discovery.

Services should be created before the Proxy replication controller.

                                               PUBLIC IP
                                                   |
                                                   |
                  +--------------------------------v--------------------------------+
                  | K8S CLUSTER                    |                                |
                  |                   +------------v------------+                   |
                  |                   | SERVICE PROXY     HTTPS |                   |
                  |                   +-------------------------+                   |
                  |                   +-------------------------+                   |
                  |                   | REPLICATION CONTROLLER  |                   |
                  |                   |                         |                   |
                  |                   | POD         POD         |                   |
                  |                   | +---------+ +---------+ |                   |
                  |                   | |  PROXY  | |  PROXY  | |                   |
                  |                   | |  NGINX  | |  NGINX  | |                   |
                  |                   | +---------+ +---------+ |                   |
                  |                   +-------------------------+                   |
                  |                          |           |                          |
                  |  +-----------------------v---+   +---v-----------------------+  |
                  |  | SERVICE SITE ONE     HTTP |   | SERVICE SITE TWO     HTTP |  |
                  |  +---------------------------+   +---------------------------+  |
                  |  +---------------------------+   +---------------------------+  |
                  |  | REPLICATION CONTROLLER    |   | REPLICATION CONTROLLER    |  |
                  |  |                           |   |                           |  |
                  |  | POD          POD          |   | POD         POD           |  |
                  |  | +----------+ +----------+ |   | +----------+ +----------+ |  |
                  |  | | SITE ONE | | SITE ONE | |   | | SITE TWO | | SITE TWO | |  |
                  |  | |  NGINX   | |  NGINX   | |   | |  NGINX   | |  NGINX   | |  |
                  |  | +----------+ +----------+ |   | +----------+ +----------+ |  |
                  |  +---------------------------+   +---------------------------+  |
                  |                                                                 |
                  +-----------------------------------------------------------------+

Getting started

1. Run a Kubernetes cluster locally:

Make sure to have access to GCloud container registry, images will be pushed on their container registry.

a. Install dependencies, run cluster

https://github.com/kubernetes/kubernetes/blob/master/docs/getting-started-guides/locally.md

Install necessary dependencies (Go, ETCD, Docker), clone the Kubernetes repo, then:

hack/local-up-cluster.sh
b. Setup K8S context

In a new shell:

Make sure Kubectl is in you path: (path/to/kubernetes/repo/cluster/kubectl.sh)

cluster/kubectl.sh config set-cluster local --server=http://127.0.0.1:8080 --insecure-skip-tls-verify=true
cluster/kubectl.sh config set-context local --cluster=local
cluster/kubectl.sh config use-context local
2. Run startup script (build images, push to GCloud container registry, create replications controllers and services)

To how what is happening in your cluster, you can run the following command in a different terminal:

# Show available pods
watch -n1 'cluster/kubectl.sh get pods'

And in another terminal the startup script:

/bin/bash startup.sh
3. Test
curl -k -H "Host: www.site-one.com" https://$(kubectl get svc | grep proxy | awk '{print $2}')
curl -k -H "Host: www.site-two.com" https://$(kubectl get svc | grep proxy | awk '{print $2}')

# This command get the proxy service IP:  kubectl get svc | grep proxy | awk '{print $2}'
4. Clean up

Bring down replication controllers and services

/bin/bash cleanup.sh

kubernetes-nginx-multisite-example's People

Stargazers

 avatar  avatar Shajal Ahamed avatar 黎漫猜想 avatar  avatar Maximilien Rzepka avatar Andrei Dragomir avatar Rimantas (Rimas) Mocevicius avatar

Watchers

James Cloos avatar Etienne avatar  avatar

Forkers

jfchevrette

kubernetes-nginx-multisite-example's Issues

Images not pull

pod/proxy-5k4h9 0/1 ImagePullBackOff 0 21s
pod/proxy-wwvm4 0/1 ImagePullBackOff 0 21s
pod/site-one-l8fhl 0/1 ImagePullBackOff 0 20s
pod/site-one-xw4jj 0/1 ImagePullBackOff 0 20s
pod/site-two-99mvk 0/1 ImagePullBackOff 0 19s
pod/site-two-kwmq5 0/1 ImagePullBackOff 0 19s

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.