<p>I've Docker Desktop Kubernetes cluster setup in my local machine and it is working fine.
Now i'm trying to deploy .Net Core gRPC server and .Net core Console load generator to my cluster.</p>
<p>I'm using VisualStudio(2019)'s default template for gRPC application</p>
<p><strong>Server:</strong></p>
<p>proto file</p>
<pre><code>syntax = &quot;proto3&quot;;

option csharp_namespace = &quot;KubernetesLoadSample&quot;;

package greet;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply);
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings.
message HelloReply {
  string message = 1;
}
</code></pre>
<p>.net core gRPC application</p>
<pre><code>public class GreeterService : Greeter.GreeterBase
{
    private readonly ILogger&lt;GreeterService&gt; _logger;
    public GreeterService(ILogger&lt;GreeterService&gt; logger)
    {
        _logger = logger;
    }

    public override Task&lt;HelloReply&gt; SayHello(HelloRequest request, ServerCallContext context)
    {
        _logger.LogInformation(&quot;Compute started&quot;);
        double result = 0;
        for (int i = 0; i &lt; 10000; i++)
        {
            for (int j = 0; j &lt; i; j++)
            {
                result += Math.Sqrt(i) + Math.Sqrt(j);
            }
        }
        return Task.FromResult(new HelloReply
        {
            Message = &quot;Completed&quot;
        }); ;
    }
}
</code></pre>
<p>and DockerFile for this project as follows,</p>
<pre><code>FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY [&quot;KubernetesLoadSample.csproj&quot;, &quot;KubernetesLoadSample/&quot;]
RUN dotnet restore &quot;KubernetesLoadSample/KubernetesLoadSample.csproj&quot;

WORKDIR &quot;/src/KubernetesLoadSample&quot;
COPY . .
RUN dotnet build &quot;KubernetesLoadSample.csproj&quot; -c Release -o /app/build

FROM build AS publish
RUN dotnet publish &quot;KubernetesLoadSample.csproj&quot; -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT [&quot;dotnet&quot;, &quot;KubernetesLoadSample.dll&quot;]
</code></pre>
<p>i was able to check this image working locally using</p>
<pre><code>PS C:\Users\user&gt; docker run -it -p 8000:80 kubernetesloadsample:latest
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /app
info: KubernetesLoadSample.GreeterService[0]
      Compute started // called from BloomRPC Client
</code></pre>
<p><strong>Client</strong></p>
<p>Client is a .net console application, that calls server in a loop</p>
<pre><code>    static async Task Main(string[] args)
    {
        var grpcServer = Environment.GetEnvironmentVariable(&quot;GRPC_SERVER&quot;);
        Channel channel = new Channel($&quot;{grpcServer}&quot;, ChannelCredentials.Insecure);

        Console.WriteLine($&quot;Sending load to port {grpcServer}&quot;);
        while(true)
        {
            try
            {
                var client = new Greeter.GreeterClient(channel);
                var reply = await client.SayHelloAsync(
                                  new HelloRequest { Name = &quot;GreeterClient&quot; });

                Console.WriteLine(&quot;result: &quot; + reply.Message);
                await Task.Delay(1000);
            }
            catch (Exception ex)
            {
                Console.WriteLine($&quot;{DateTime.UtcNow} : tried to connect : {grpcServer}  Crashed : {ex.Message}&quot;);
            }
        }
    }
</code></pre>
<p>Docker file for client:</p>
<pre><code>FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY [&quot;GrpcClientConsole.csproj&quot;, &quot;GrpcClientConsole/&quot;]
RUN dotnet restore &quot;GrpcClientConsole/GrpcClientConsole.csproj&quot;

WORKDIR &quot;/src/GrpcClientConsole&quot;
COPY . .
RUN dotnet build &quot;GrpcClientConsole.csproj&quot; -c Release -o /app/build

FROM build AS publish
RUN dotnet publish &quot;GrpcClientConsole.csproj&quot; -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT [&quot;dotnet&quot;, &quot;GrpcClientConsole.dll&quot;]
</code></pre>
<p>and deployment file as follows,</p>
<pre><code>---
apiVersion: v1
kind: Namespace
metadata:
  name: core-load
---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: compute-server
  namespace: core-load
spec:
  replicas: 4
  selector:
    matchLabels:
      app: compute-server-svc
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: compute-server-svc
    spec:
      containers:
      - env:
        image: kubernetesloadsample:latest
        imagePullPolicy: Never
        name: compute-server-svc
        ports:
        - containerPort: 80
          name: grpc
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  name: compute-server-svc
  namespace: core-load
spec:
  clusterIP: None
  
  ports:
  - name: grpc
    port: 5000
    targetPort: 80
    protocol: TCP
  selector:
    app: compute-server-svc
---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: compute-client
  namespace: core-load
spec:
  replicas: 1
  selector:
  
    matchLabels:
      app: compute-client
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: compute-client
    spec:
      containers:
      - env:
        - name: GRPC_SERVER
          value: compute-server-svc.core-load.svc.cluster.local:5000
        image: grpc-client-console:latest
        imagePullPolicy: Never
        name: compute-client
        resources: {}
status: {}
---
</code></pre>
<p><strong>Problem</strong></p>
<p>client is not able to connect gRPC server with this  compute-server-svc.core-load.svc.cluster.local:5000 name. I tried  compute-server-svc.core-load this as well, but facing below issue</p>
<pre><code>PS E:\study\core\k8sgrpc\KubernetesLoadSample&gt; k get pods -n core-load
NAME                              READY   STATUS    RESTARTS   AGE
compute-client-bff5f666-cjwf5     1/1     Running   0          15s
compute-server-545567f589-5blkv   1/1     Running   0          15s
compute-server-545567f589-bv4r2   1/1     Running   0          15s
compute-server-545567f589-mdp2x   1/1     Running   0          15s
compute-server-545567f589-wdff5   1/1     Running   0          15s
PS E:\study\core\k8sgrpc\KubernetesLoadSample&gt; k logs compute-client-bff5f666-cjwf5 -n  core-load --tail 5
07/09/2021 17:18:35 : tried to connect : compute-server-svc.core-load.svc.cluster.local:5000 Crashed : Status(StatusCode=Unavailable, Detail=&quot;failed to connect to all addresses&quot;)
07/09/2021 17:18:35 : tried to connect : compute-server-svc.core-load.svc.cluster.local:5000 Crashed : Status(StatusCode=Unavailable, Detail=&quot;failed to connect to all addresses&quot;)
07/09/2021 17:18:35 : tried to connect : compute-server-svc.core-load.svc.cluster.local:5000 Crashed : Status(StatusCode=Unavailable, Detail=&quot;failed to connect to all addresses&quot;)
07/09/2021 17:18:35 : tried to connect : compute-server-svc.core-load.svc.cluster.local:5000 Crashed : Status(StatusCode=Unavailable, Detail=&quot;failed to connect to all addresses&quot;)
07/09/2021 17:18:35 : tried to connect : compute-server-svc.core-load.svc.cluster.local:5000 Crashed : Status(StatusCode=Unavailable, Detail=&quot;failed to connect to all addresses&quot;)
</code></pre>
<p>I didnt get any solution from the stackoverflow questions similar to this, so im creating this.</p>
<p>Can anyone please let me know what i've missed or doing wrong?</p>
<p>TIA</p>

WPFUser
<p>You defined your service with the:</p>
<pre><code>clusterIP: None
</code></pre>
<p>which is used to create an headless service. This may be the cause of the problem, so removing it could resolve your error.</p>
<hr />
<p>When you create a <code>ClusterIP</code> type service (which is the default type) Kubernetes automatically assign the service a virtual IP (called also cluster IP, as the type suggests) which is then used to proxy communication towards the Pods selected by the service in question.</p>
<p>This means that there is a &quot;new&quot; IP address (visible only from inside the cluster), different from the various IP assigned to the Pods (or single Pod) behind the service, which then routes the traffic with a sort of load balancing to the Pods standing behind.</p>
<p>If you specify</p>
<pre><code>clusterIP: None
</code></pre>
<p>you create an headless service. You are basically telling Kubernetes that you don't want a virtual IP to be assigned to the service. There is no load balancing by the proxy as there is no IP to load balance.</p>
<p>Instead, the DNS configuration will return A records (the IP addresses) for each of the Pods behind (selected) by the service.</p>
<p>This can be useful if your application needs to discover each Pod behind the service and then do whatever they want with the IP address on their own.</p>
<p>Maybe to load balance with an internal implementation, maybe because different Pods (behidn the same service) are used for different things.. or maybe because each one of those Pods wants to discover the other Pods (think about multi-instance primary applications such as Kafka or Zookeeper, for example)</p>
<hr />
<p>I'm not sure on what exactly could be your problem, it may depends on how the hostname is resolved by that particular app.. but you shouldn't use an headless service, unless you have the necessity to decide which of the Pods selected by the svc you want to contact.</p>
<p>Using DNS round robin to load balance is also (almost always) not a good idea compared to a virtual IP.. as applications could cache the DNS resolution and, if Pods then change IP address (since Pods are ephimeral, they change IP address whenever they restart, for example), there could be network problems in reaching them.. and more.</p>
<p>There's a huge amount of info in the docs:
<a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>
