...
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) |
---|
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 ## You are now logged into the master node, and you can check the connection to the pod with a simple curl command. |
---|
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
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.
...