-1

I have some pods running some services (e.g. an authentication service). It sends requests to the client service via grpc. When the client service is restarted, the IP address of the pod changes. And then the authentication service receives a new IP client of the service. However, there is no reconnect. How can I reconnect again?

Peyman
  • 3,059
  • 1
  • 33
  • 68
mide
  • 23
  • 3
  • 3
    `k8s` services is literally designed to track pods changing IPs. So use a DNS name not a IP when addressing your services. – colm.anseo Jul 20 '21 at 10:51

2 Answers2

2

I would recommend that your read Kubernetes basics to get familiar with some of the core objects, it really helps to get a general picture.

Related to your problem, I would read about Services: https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/

You'll likely want to use a Service.

Peyman
  • 3,059
  • 1
  • 33
  • 68
2

As mentioned by @colm.anseo, kubernetes services are designed to track pods changing IPs. So instead of IP addresses use a DNS name when addressing the services. gRPC will automatically reconnect to new addresses when DNS is updated, and DNS is refreshed periodically (on connection errors; at most every 30 seconds, and with exponential backoff if there are no addresses currently connected). Each reconnect attempt implies resolving the DNS address, although it may not detect the new address immediately because of the TTL (time-to-live) of the old DNS entry. Refer to DNS for Services and Pods for information.

Jyothi Kiranmayi
  • 2,090
  • 5
  • 14