2
votes

I have created the replication controller in Kubernetes with the following configuration:

{
   "kind":"ReplicationController",
   "apiVersion":"v1",
   "metadata":{
      "name":"guestbook",
      "labels":{
         "app":"guestbook"
      }
   },
   "spec":{
      "replicas":1,
      "selector":{
         "app":"guestbook"
      },
      "template":{
         "metadata":{
            "labels":{
               "app":"guestbook"
            }
         },
         "spec":{
            "containers":[
               {
                  "name":"guestbook",
                  "image":"username/fsharp-microservice:v1",
                  "ports":[
                     {
                        "name":"http-server",
                        "containerPort":3000
                     }
                  ],
                  "command": ["fsharpi", "/home/SuaveServer.fsx"]
               }
            ]
         }
      }
   }
}

The code of the service that is running on the port 3000 is basically this:

#r "Suave.dll"
#r "Mono.Posix.dll"
open Suave
open Suave.Http
open Suave.Successful
open System
open System.Net
open System.Threading
open System.Diagnostics
open Mono.Unix
open Mono.Unix.Native

let app = OK "PONG"

let port = 3000us
let config =
  { defaultConfig with
     bindings = [ HttpBinding.mk HTTP IPAddress.Loopback port ]
     bufferSize = 8192
     maxOps = 10000
  }

open System.Text.RegularExpressions

let cts = new CancellationTokenSource()
let listening, server = startWebServerAsync config app
Async.Start(server, cts.Token)

Console.WriteLine("Server should be started at this point")
Console.ReadLine()

After I created the service I can see the pod:

$kubectl create -f guestbook.json
replicationcontroller "guestbook" created
$ kubectl get pods
NAME                   READY     STATUS             RESTARTS   AGE
guestbook-0b9py        1/1       Running            0          32m

I want to access my web service and create the service with type=LoadBalancer that will expose the 3000 port with the following configuration:

{
   "kind":"Service",
   "apiVersion":"v1",
   "metadata":{
      "name":"guestbook",
      "labels":{
         "app":"guestbook"
      }
   },
   "spec":{
      "ports": [
         {
           "port":3000,
           "targetPort":"http-server"
         }
      ],
      "selector":{
         "app":"guestbook"
      },
      "type": "LoadBalancer"
   }
}

Here is the result:

$ kubectl create -f guestbook-service.json
service "guestbook" created
$ kubectl get services
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
guestbook    10.0.82.40                 3000/TCP   7s
kubernetes   10.0.0.1     <none>        443/TCP    3h
$ kubectl describe services
Name:           guestbook
Namespace:      default
Labels:         app=guestbook
Selector:       app=guestbook
Type:           LoadBalancer
IP:         10.0.82.40
LoadBalancer Ingress:   a43eee4a008cf11e68f210a4fa30c03e-1918213320.us-west-2.elb.amazonaws.com
Port:           <unset> 3000/TCP
NodePort:       <unset> 30877/TCP
Endpoints:      10.244.1.6:3000
Session Affinity:   None
Events:
  FirstSeen LastSeen    Count   From            SubobjectPath   Type        Reason          Message
  --------- --------    -----   ----            -------------   --------    ------          -------
  18s       18s     1   {service-controller }           Normal      CreatingLoadBalancer    Creating load balancer
  17s       17s     1   {service-controller }           Normal      CreatedLoadBalancer Created load balancer


Name:           kubernetes
Namespace:      default
Labels:         component=apiserver,provider=kubernetes
Selector:       <none>
Type:           ClusterIP
IP:         10.0.0.1
Port:           https   443/TCP
Endpoints:      172.20.0.9:443
Session Affinity:   None
No events.

The "External IP" column is empty

I have tried to access the service using "LoadBalancer Ingress" but DNS name can't be resolved.

If I check in the AWS console - load balancer is created (but in the details panel there is a message "0 of 2 instances in service" because of health-checks).

I have also tried to expose my RC using kubectl expose --type=Load-Balancer, but result is the same.

What is the problem?

1
Can you each the pod on its internal cluster IP on port 3000? Can you reach the service on its internal IP and port 3000? Is AWS configured to use port 3000 as well?Timo Reimann
@TimoReimann AWS is all open in the settings of EC2 instances, I've checked the rules of the security groups. Will try the internal and cluster IPs in a bitexperimenter
@Timoreimann No, can't reach it using the internal IP and cluster IP. AWS is configured to use the port, it's all open. What else might it be and why I can't reach anything?experimenter
@TimoReimann Hey friend, I made it work. The problem was in the actual microservice. 0.0.0.0 instead of 127.0.0.1 in the code of the web server.experimenter
Would you post an answer to your question yourself so that future generations will know?Timo Reimann

1 Answers

5
votes

I fixed the error.

The thing was in the actual service. It needs to be listening on 0.0.0.0 instead of 127.0.0.1 or localhost. That way it will listen on every available network interface. More details on the difference between 0.0.0.0 and 127.0.0.1: https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1