| Table of Contents |
| Part 1: Basis Part 2: Kubernetes Part 3: Ingress Controller Part 4: Design & Conclusions |
Let's say you'r goal is to run one or more websites. We'll assume you know enough of Linux to set up a dedicated server, event though we won't. Compared to a traditional dedicated server we'll also get:
We'll use two key technologies one built on top of the other:
Even those both of these areopen source and can run on pretty much any Linux, we'll useGoogle Cloud Platform to simplify set up and maintenance.
If you know Docker you can skip this paragraph.
Practically Docker works a little bit like a lightweightvirtual machine but technologically very different. Common scenario is to create a text file namedDockerfile with a list of commands to run one top of a base image likeDebian, or a premade service likeNginx,MySQL,PHP...
Unlike a Virtual Machine, you can run thouthands of Docker images on a single machine without issue. To build or run a Dockerimage you need to install Docker. Then your image will run exactly the same on all OSes running Docker. A running (or previously running) instance of animage is called a Dockercontainer (that is why some people talk aboutcontainerizing applications, meaning making a Docker image in which they can properly run). Processes inside the container cannot access more of the host machine unless specifically allowed; this isn't as strong as a virtual machine so don't run processes asroot even from within the container. Docker runs mostly from the CLI and most Dockerized (aka containerized) application runheadless (i.e. without GUI) which is perfect for any website component.
Dockerfile
FROM nginx:stable-alpineRUN apk add --update ca-certificates php-pda_mysql && rm -rf /var/cache/apk*COPY . /usr/share/nginx/htmlHere we start from an Nginx image that is itself base onAlpine Linux. Now on a Linux let's install Docker, build, and start our web server:
curl -sSL https://get.docker.com/ | shdocker build -t my-frontend-image .docker run -d -p 127.0.0.1:8080:80 my-frontend-imageNow you can open your browser an go tohttp://127.0.0.1:8080 and you should be able to access the server along with an file below the directory containing yourDockerfile.
docker-compose is a small official binary that simplifies commands for a set of linked Docker images. It's optional but it simplifies things a bit.
Example of linking our Nginx to MySQL (yes it's kind of stupid as you'd probably link Nginx to Python or PHP and link those to MySQL but you get the idea):
docker-compose.yml
version: '2'services: frontend: build: . # By specifying 'build' and 'image' fields we force the built image tag name. image: my-frontend-image mount: .:/usr/share/nginx/html:ro links: - db db: image: mysql:5.7Let's installdocker-compose and build and run both images (note from within the Nginx container a host nameddb will be created an it'll point to the container running MySQL):
curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` > docker-composechmod +x docker-compose./docker-compose up -dWe did another thing here which is that we asked to mount the current directory as/usr/share/nginx/html (asread-only). This means that any change done to the files will be reflected inside the container without having to re-create your Docker image (i.e. docker build isn't required to pick up changes). This is something very useful during development, but we want our Docker image to contain all necessary files for later deployment in production on the server.
Now let's see how to deploy on a cluster in the cloud (can be a single machine or multiple cloud computers).