Exercise 3 - Networking¶
Each Pod
has its own IP address in order to access the application on it over the network.
However,Pods
are non-permanent resources which are created and destroyed by the Deployment
dynamically.
Therefore the IP addresses of your application are changing dynamically too and it is difficult to keeps track of which IP address to connect to.
Services¶
The Service
is an abstract way to expose an application running on a set of Pods
and load-balance the requests across them.
Instead of connecting to the IP addresses of the Pods
directly you can connect instead to its Service
.
Check out the Kubernetes Documentation for more information about Services
.
Routes¶
The Route
allows to expose services through HTTP(S) via a public DNS entry. This is needed to make Services
accessible from outside of the cluster.
Check out the OpenShift Documentation for more information about Routes
.
Note
For each exercise you can choose and only have to do either the 'Web Console' or the 'Command Line Interface (CLI)' section in oder to complete the exercise.
Create a Service
¶
- Switch to the 'Administrator' view using the dropdown menu at .
- Navigate to 'Networking' → 'Services' .
- Switch to the your project using the dropdown menu at . In each of the exercise make sure that you are in your project context before you are making any changes.
- Press 'Create Service' .
- Let's create a
Service
for the port8080
. Copy the followingService
definition file to the editor and replace<port>
and<app label>
with the correct value:More detailed information about theapiVersion: v1 kind: Service metadata: name: httpd spec: selector: app: <app label> ports: - protocol: TCP port: <port>
Service
definition file can be found in the Tab at . - Press 'Create' .
Create a Route
¶
- Navigate to 'Networking' → 'Routes' .
- Press 'Create Route' .
- Set the 'Name' to
httpd
. - Select the 'Service' you have created above in .
- Choose the 'Target Port'
8080
from the dropdown menu . - Let's secure the
Route
by enabling the checkbox and selecting 'Edge' for 'TLS Termination' . - Scroll until the end of the page and press 'Create'.
- Open the link at the 'Route Details' page in order to test the route.
Important
At the beginning of the exercise make sure that you are in your project context.
oc project <project name>
Create a Service
¶
- Create a
Service
for the port8080
of theDeployment
that we have created in Exercise 2:oc expose deployment <deployment name> --port=<port>
-
Inspect the
Service
using theoc get
or theoc describe
command.oc get service -o wide
oc describe service <service name>
How many endpoints are connected to your
Service
and why?Solution:
There are 2 endpoints connected to your
Service
, you can figure that out by using theoc describe
command.[~] $ oc describe service <service name> ... Endpoints: <IP endpoint 1>:8080,<IP endpoint 2>:8080 ...
The reason that there are 2 endpoints is that we have 2 replicas configured in the
Deployment
. Let's compare the IP addresses of the endpoints with the IP address of eachPod
. The IP address of thePods
can be retrieved using theoc get pods -o wide
command. As you can see theService
is successfully connected to allPods
of yourDeployment
.
Create a Route
¶
- Create a
Route
in order to make theService
accessible from outside of the cluster.oc create route edge httpd --service=<service name>
- Inspect the new
Route
using theoc get
command.oc get routes
- Try to connect to the
https://HOST
of theRoute
using the browser in order to test the route.