Configuring External Services with Kubernetes Ingress

In this part, we will focus on configuring and deploying the Express service, which is quite similar to the MongoDB service configuration, especially in terms of ports. Both services use the same port settings: the service port is set to 8081, and the target port corresponds to the container port where the application listens.

To make these services externally accessible, you need to perform two key steps:

Step 1: Service Type
In the specification section of the service configuration, right below the selector, you should add a type. Set the type of the external service to LoadBalancer. However, it’s worth noting that the term “LoadBalancer” can be a bit confusing because internal services also act as load balancers. This external LoadBalancer type’s primary function is to accept external requests and assign the service an external IP address.

Step 2: Node Port
You’ll also need to specify a nodePort. This is the port through which the external IP address will be accessible. It’s essential to choose a nodePort within the range of 30,000 to 32,000 (in this example, we’ll use the minimum value, 30,000).

Here is the updated configuration for your external service (Express service) in the service.yaml file:

apiVersion: v1
kind: Service
  name: express-service
    app: express
    - protocol: TCP
      port: 8081  # Service port
      targetPort: 8081  # Container port
  type: LoadBalancer  # Step 1: Set the service type to LoadBalancer
    - <your_external_ip>  # Replace with your external IP address
  nodePort: 30000  # Step 2: Specify the nodePort (within the allowed range)

Now, let’s apply the updated configuration:

kubectl apply -f service.yaml

After creating the service with these modifications, you should see that it is of type LoadBalancer when you run kubectl get services.

Please note that when you’re in a MiniKube environment, the external IP might show as “pending.” In such cases, you can use the minikube service command to assign an external IP address for your service. After this step, you can access your Express application through a web browser using the assigned external IP address and the nodePort you specified (in this example, 30,000).

With this setup, changes you make in your Express application will follow a path from the external request to the Express service, which connects to the MongoDB service through the internal service, eventually reaching the MongoDB Pod. This arrangement allows your simple application setup to function effectively within a Kubernetes cluster.

In the following parts of the course, you can explore more advanced configurations and practices for working with Kubernetes.

Ingress controller in your minikube cluster.

Now, let’s create an Ingress resource to define the routing rules. You can create an Ingress configuration like this:

kind: Ingress
  name: my-ingress
    - host:
          - path: /app
            pathType: Prefix
                name: my-app-service
                  number: 80

This Ingress configuration defines that requests to with a path starting with /app should be forwarded to the service named my-app-service on port 80.

Make sure to replace with your actual domain or subdomain and my-app-service with the name of your service.

Apply this configuration to your minikube cluster using the kubectl apply command:

kubectl apply -f your-ingress-config.yaml

Once you’ve done that, Ingress will route external requests to your services in the cluster based on the rules you’ve defined. Please note that you might need to set up DNS records for your domain to point to the IP address where your Ingress controller is running.

Keep in mind that Ingress controllers might differ slightly depending on the specific one you choose, but the basic idea remains the same. The Ingress controller listens for incoming requests, evaluates the Ingress rules, and routes the requests accordingly to the appropriate services within your cluster.

Leave a Comment

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

Scroll to Top