Part 2: K3s and three simple applications - 42lan/inception-of-things GitHub Wiki
Three web applications are run in one K3s server instance and accessible depending on the Host used when making a request to the IP address 192.168.42.11.
Application 1 has 1 replica and is accessible if request includes a header Host: app1.com
Application 2 has 3 replicas and is accessible if request includes a header Host: app2.com
Application 3 has 1 replica and is accessible by default or contains undefined value of request header Host.
Expand
Expand
vagrant up
Bringing machine 'suchoS' up with 'virtualbox' provider...
==> suchoS: Importing base box 'centos/7'...
[...]
suchoS: [INFO] systemd: Starting k3s
suchoS: service/app-one created
suchoS: deployment.apps/app-one created
suchoS: service/app-two created
suchoS: deployment.apps/app-two created
suchoS: service/app-three created
suchoS: deployment.apps/app-three created
suchoS: ingress.networking.k8s.io/ingress-applications createdExpand
vagrant ssh suchoS --command "kubectl get all"
NAME READY STATUS RESTARTS AGE
pod/app-one-7454877f6d-ndx7f 1/1 Running 0 36m
pod/app-two-867df7fb47-8rb9b 1/1 Running 0 36m
pod/app-two-867df7fb47-tsrdt 1/1 Running 0 36m
pod/app-three-5467985dbb-cg2n7 1/1 Running 0 36m
pod/app-two-867df7fb47-tzk98 1/1 Running 0 36m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/app-one ClusterIP 10.43.246.0 <none> 80/TCP 37m
service/app-two ClusterIP 10.43.99.33 <none> 80/TCP 37m
service/app-three ClusterIP 10.43.77.88 <none> 80/TCP 37m
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 37m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/app-one 1/1 1 1 37m
deployment.apps/app-three 1/1 1 1 37m
deployment.apps/app-two 3/3 3 3 37m
NAME DESIRED CURRENT READY AGE
replicaset.apps/app-one-7454877f6d 1 1 1 36m
replicaset.apps/app-three-5467985dbb 1 1 1 36m
replicaset.apps/app-two-867df7fb47 3 3 3 36m
Connection to 127.0.0.1 closed.Expand
vagrant ssh suchoS --command "kubectl describe ingress"
Name: ingress-applications
Namespace: default
Address: 192.168.42.110
Default backend: app-three:80 (10.42.0.9:8080)
Rules:
Host Path Backends
---- ---- --------
app1.com
/ app-one:80 (10.42.0.2:8080)
app2.com
/ app-two:80 (10.42.0.11:8080,10.42.0.5:8080,10.42.0.6:8080)
*
/ app-three:80 (10.42.0.9:8080)
Annotations: <none>
Events: <none>
Connection to 127.0.0.1 closed.Using curl
app1 with one replica
[~]$ curl -sH "Host:app1.com" 164.92.153.174 | grep app Hello from app1. <td>app-one-7454877f6d-ndx7f</td>app2 with three replicas
[~]$ curl -sH "Host:app2.com" 164.92.153.174 | grep app Hello from app2. <td>app-two-867df7fb47-tsrdt</td> [~]$ curl -sH "Host:app2.com" 164.92.153.174 | grep app Hello from app2. <td>app-two-867df7fb47-8rb9b</td> [~]$ curl -sH "Host:app2.com" 164.92.153.174 | grep app Hello from app2. <td>app-two-867df7fb47-tzk98</td>app3 with one replica as default application
[~]$ curl -sH "Host:app3.com" 164.92.153.174 | grep app Hello from app3. <td>app-three-5467985dbb-cg2n7</td> [~]$ curl -sH "Host:42.fr" 164.92.153.174 | grep app Hello from app3. <td>app-three-5467985dbb-cg2n7</td> [~]$ curl -s 164.92.153.174 | grep app Hello from app3. <td>app-three-5467985dbb-cg2n7</td>
Using Firefox
Install a plugin ModHeader for Firefox and add Host header to the request.
app1 with one replica
![]()
app2 with three replicas
app1 replica 1
![]()
app1 replica 2
![]()
app1 replica 3
![]()
app3 with one replica as default application
![]()
![]()