<p>I am trying to make GRPC work in a <code>digitalocean</code> <code>Kubernetes</code> cluster - but am still to succeed.</p>
<blockquote>
<p>PS: Apologies for the long content</p>
</blockquote>
<p>I have found some content regarding this but those revolve around some ingress. For me, these are internal services.</p>
<p>I have a <code>.proto</code> defined as such:</p>
<pre><code>syntax = &quot;proto3&quot;;
package imgproto;
option go_package = &quot;.;imgproto&quot;;

import &quot;google/protobuf/duration.proto&quot;;
import &quot;google/protobuf/timestamp.proto&quot;;

service ImaginaryServer {
  rpc Ping(PingPayload) returns (PongPayload) {}
}

message PingPayload {
  google.protobuf.Timestamp ts = 1;
}
message PongPayload {
  google.protobuf.Timestamp ts = 1;
}
</code></pre>
<p>After running <code>proto-gen-go</code>, I populate the <code>implementation</code> with:</p>
<pre><code>type ImaginaryServerImpl struct {
    imgproto.UnimplementedImaginaryServer
}


func (s *ImaginaryServerImpl) Ping(_ context.Context, in *imgproto.PingPayload) (*imgproto.PongPayload, error) {
    fmt.Printf(&quot;ImaginaryServerImpl.Ping: %v\n&quot;, in)
    return &amp;imgproto.PongPayload{
        Ts: timestamppb.New(time.Now()),
    }, nil
}

</code></pre>
<p>Create and register it to a GRPC server:</p>
<pre><code>grpcServer := grpc.NewServer()
imgproto.RegisterImaginaryServer(grpcServer, &amp;ImaginaryServerImpl{})
</code></pre>
<p>And start the server:</p>
<pre><code>grpcListener, err := net.Listen(&quot;tcp&quot;, fmt.Sprintf(&quot;:%d&quot;, constants.PORT_GRPC))
if err != nil {
    return err
}

go func() {
    if err := grpcServer.Serve(grpcListener); err != nil {
        fmt.Println(&quot;GRPC Server startup failed with&quot;, err)
    }
}()

&lt;-ctx.Done()
grpcServer.GracefulStop()
</code></pre>
<p>I wrote up the client as:</p>
<pre><code>grpcConnection, err := grpc.Dial(
    endpoint,
    grpc.WithBlock(),
    grpc.WithTransportCredentials(insecure.NewCredentials()),
    grpc.WithUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
        fmt.Println(&quot;Calling GRPC:&quot;, method, req, reply, invoker)
        return nil
    }))
if err != nil {
    return ctx, err
}

client := pmqproto.NewImaginaryClient(grpcConnection)

fmt.Println(&quot; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; PING:&quot;)
pong, pingErr := client.Ping(ctx, &amp;imgproto.PingPayload{Ts: timestamppb.Now()}, grpc.WaitForReady(false))
if pingErr != nil {
    fmt.Println(pingErr)
}
fmt.Println(&quot; &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; PONG: &quot;, pong.Ts.AsTime().String())
</code></pre>
<p>But it looks like the client is returning without actually invoking the RPC.</p>
<p><code>Log</code> that I am seeing in the client:</p>
<pre><code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; PING:
Calling GRPC: /imgproto.ImaginaryServer/Ping ts:{seconds:1666113879  nanos:778900352}  0x127aa60
&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; PONG:  1970-01-01 00:00:00 +0000 UTC
</code></pre>
<blockquote>
<p>There are no logs in the server.</p>
</blockquote>
<p>My <code>k8s</code> yaml is as such:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: reality
  namespace: reality-ns
spec:
  type: ClusterIP
  selector:
    app: reality
  ports:
    - name: grpc
      protocol: TCP
      port: 6772
      targetPort: 6772
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: reality
  namespace: reality-ns
  labels:
    app: reality
spec:
  selector:
    matchLabels:
      app: reality
  template:
    metadata:
      labels:
        app: reality
    spec:
      containers:
        - name: reality
          image: registry.example.com/binaek/reality
          imagePullPolicy: Always
          command: [&quot;cmd&quot;]
          ports:
            - name: grpc
              containerPort: 6772

</code></pre>
<p>I am not able to locate what I am doing wrong. Desperately need help at this point.</p>
<blockquote>
<p>The image uses <code>gcr.io/distroless/base</code> as it's base.</p>
</blockquote>

Binaek Sarkar
<p>Your interceptor usage is likely preventing execution of the RPC.</p>
<pre><code>// When a unary interceptor(s) is set on a ClientConn, gRPC
// delegates all unary RPC invocations to the interceptor, and it is the
// responsibility of the interceptor to call invoker to complete the processing
// of the RPC.
</code></pre>
<p><a href="https://github.com/grpc/grpc-go/blob/9127159caf5a3879dad56b795938fde3bc0a7eaa/interceptor.go#L31-L34" rel="nofollow noreferrer">https://github.com/grpc/grpc-go/blob/9127159caf5a3879dad56b795938fde3bc0a7eaa/interceptor.go#L31-L34</a></p>
<p>So your interceptor function should instead look like:</p>
<pre><code>grpc.WithUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
    fmt.Println(&quot;Calling GRPC:&quot;, method, req, reply, invoker)
    return invoker(ctx, method, req, reply, cc, opts...)
}))
</code></pre>
