All HowTo's Kubernetes & Docker Linux Ubuntu, Mint & Debian Linux

Kubernetes (MicroK8s) Part 3 – Exposing Applications on Ubuntu 20.04

This article continues from Part 2 – Replica Sets and Scaling.

Our objective in this article is to get an application exposed to the wider network on an IP address of the host and a port of our choice. The IP address will be “” and our port of choice will be “30036”.

We’re going to expose a dotNet application which, according to its documentation, listens on port “8080”.

Put the following content into a new file called “dotnet-rs.yaml”:

apiVersion: apps/v1
kind: ReplicaSet
  name: dotnet-hello-rs # This is what our Service will point to. 
  replicas: 5 # This is the number of instances we want for this app.
      app: dotnet-hello-rs
        app: dotnet-hello-rs
      - name: dotnet-hello-rs
        image: appsvctest/dotnetcore # This is our image to execute. 
        - containerPort: 8080 # Doco for this image says it's listening on this port. 

Put the following content into a new file called “dotnet-service.yaml”:

apiVersion: v1
kind: Service
  name: dotnet-hello-service
    app: dotnet-hello-service
  type: NodePort
    - name: http
      protocol: TCP
      nodePort: 30036 # The port our networked devices will look on for the application. 
      port: 9090 
      targetPort: 8080 # The port of the target ReplicaSet. 
    app: dotnet-hello-rs # This is the name or the target ReplicaSet. 

Now start the ReplicaSet and Service objects.

sudo microk8s kubectl apply -f dotnet-rs.yaml
sudo microk8s kubectl apply -f dotnet-service.yaml

Validate our ReplicaSet:

sudo microk8s kubectl get rs -o wide
NAME              DESIRED   CURRENT   READY   AGE   CONTAINERS        IMAGES                  SELECTOR
dotnet-hello-rs   5         5         5       15m   dotnet-hello-rs   appsvctest/dotnetcore   app=dotnet-hello-rs

Validate our Service:

sudo microk8s kubectl get service -o wide
NAME                   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE   SELECTOR
kubernetes             ClusterIP           443/TCP          32h   
dotnet-hello-service   NodePort           9090:30036/TCP   11m   app=dotnet-hello-rs

Ensure your firewall allows port “30036” through.

sudo ufw allow 30036

From the Kubernetes host, test that you can get to the Pod:

curl -v

Now test from a networked machine (some other machine on your LAN):

curl -v

You should get the output of the dotNet application.

Leave a Reply

Your email address will not be published. Required fields are marked *