Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The network in kubernetes  usually will have a topology like the figure below. In this example, we will start from the bottom, which are pods, and will build up the network.


Example network topology (image from this article)

Image Modified


Step

...

0: have a webserver docker image ready with the contents of your web page

  • There are various ways to deploy web server on the k8s. Here we assume that you have a docker image of the web server and all the contents of your pages. 
  • We will use "registry.kasi.re.kr/uwife/uwife_www" that I (Jae-Joon Lee) have personally created.
  • The image is based on nginx web server and the copy of the web pages I will serve.
  • The Dockerfile and all its contents are available at https://data.kasi.re.kr/gitlab/leejjoon/uwife-www

Step

...

1: Deployment

  • The "deployment" resource is often used when you want scalable number of pods.

...

## Let's find out the ip address of the master node and ssh in to it.

ubuntu@spherex-gw:~/git/k8s-leejjoon-test/simple_webserver_uwife$ k get nodes -o wide|grep master
spherex-k8s-10-n2fw4cjrwsza-master-0   Ready    master   24h     v1.18.2   10.0.1.125    <none>        Fedora CoreOS 32.20201004.3.0   5.8.12-200.fc32.x86_64   docker://19.3.11
ubuntu@spherex-gw:~/git/k8s-leejjoon-test/simple_webserver_uwife$ ssh core@10.0.1.125
Enter passphrase for key '/home/ubuntu/.ssh/id_rsa':  
Fedora CoreOS 32.20201004.3.0
Tracker: https://github.com/coreos/fedora-coreos-tracker
Discuss: https://discussion.fedoraproject.org/c/server/coreos/

Last login: Wed Jun  8 09:38:15 2022 from 10.0.1.58


## You are now logged into the master node, and you can check the connection to the pod with a simple curl command.

 
[core@spherex-k8s-10-n2fw4cjrwsza-master-0 ~]$ curl -I 10.100.95.194
HTTP/1.1 200 OK
Server: nginx/1.22.0
Date: Wed, 08 Jun 2022 10:44:05 GMT
Content-Type: text/html
Content-Length: 35
Last-Modified: Fri, 30 May 2014 06:14:51 GMT
Connection: keep-alive
ETag: "538821db-23"
Accept-Ranges: bytes


Step

...

2: Create a service for external connection.

  • To access the pod from outside, you need to create a service resource for it.
  • Here we will use "NodePort" type service. With the "NodePort" service, you will create a connection from a port in any of the worker nodes to the pod.

...

  • Similarly, you can assign a virtual ip by creating a "LoadBalancer" service.
  • But, for now, the loadbalancer requires floating ip assigned to it, which can limit its usage.
  • Instead, you can use Ingress resources. It can create a internal vip and/or use same ip for different services.

Step

...

3: Create am Ingress for external connection with routing.


Code Block
languageyml
themeRDark
firstline1
titleingress.yaml
linenumberstrue
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: default-internal-ingress
  annotations:
    kubernetes.io/ingress.class: "openstack"
    octavia.ingress.kubernetes.io/internal: "true"
spec:
 rules:
 - host: k8s-10.gems0.org
   http:
     paths:
     - path: /
       pathType: Prefix
       backend:
         serviceName: uwife-www
         servicePort: 80

...

  • You can setup a ssl certificate for your site and make HTTPS connection accessible, but this won't be covered here.


Step

...

4: Scale out your web page.

  • If your web page become super popular, a single web server cannot handle your traffic.
  • The virtue of kubernetes is its ease of scaling out.
  • You simply change the "replicas" number (line 6) and reapply. And you will have multiple pods serving your web page.

...