[42 ft_services] Install Nginx with Kubernetes

forhjy
2 min readNov 7, 2020

--

HTTP, HTTPS, SSH

To create k8s pods and services, you have to build docker images first, so let’s briefly look at Dockerfile first.

Docker

Dockerfile for Nginx

It is almost identical to dockerfile article I wrote, but you have to add some commands for SSH setting. Since port 22 is already in use, so I opened port 30022 instead.

Why using nginx daemon off?

For Docker containers (or for debugging), the daemon off; directive tells Nginx to stay in the foreground. For containers this is useful as best practice is for one container = one process. One server (container) has only one service. For more details check out this stack overflow link.

Config for Nginx

Remove second location block(which was for php connection) from former article I wrote.

Kubernetes

Health Check

Kubernetes check the status of each container regularly, we called it as health check. If container has problem, it automatically restart the container or exclude the container from the service.

There are two ways in health check. One is Readiness probe, which checks if the container is able to provide services. And the other is Liveness probe, checks if the container is alive or not. And there are three types of probe to execute health check. These are Command probe, HTTP probe, and TCP probe. TCP probe try to make tcp connection to assigned port, and if connection is successful, the container considered as healthy.

Nginx yaml

Check & Test

If pods and services created successfully, you can see k8s dashboards.

Check if nginx is successfully connected by cmd + click on URL or type the URL on Chrome.

SSH Login Test

ssh (ID)@(minkube ip address) -p (port number)

and enter the password you set in the Dockerfile.

--

--