简体   繁体   中英

How can I call a specific pod, in a service, from outside the kube cluster

For self-healing I want to be able to call a function on a specific pod instance from outside the kube cluster.

So... I have 2 networks, non-kube, and my kube-cluster. My kube-cluster contains one service, myapp and has 8 replicas spread across 4 nodes. If each of these pods was given a VIP 10.1.1.x where x is from 1 to 8, I want to be able to from any app running in non-kube, be able to call any of the API methods exposed in myapp, but forcing a particular replica.

Eg myapp has one REST GET method,

whatismyvip()

And from a console app running in non-kube I want to be able to ensure I get the following output, by calling the above method on the right pod.

10.1.1.4
10.1.1.6
10.1.1.8
10.1.1.2
10.1.1.5

Why would I want to do something like this? Well, generally the errors that are generated in the kube-cluster service are server errors due to bad data / configuration, rather than the system "going down", ie 500 errors, and so I want the client to be smart enough to go

"ok, i got an error from 10.1.1.2, i will try 10.1.1.3"

I'd prefer to do this natively in kubernetes (even if it means custom IngressController) rather than sidecar service mesh, Envoys et al.

Create a loadbalanced service that fronts your replicaset of 8 pods. Define a liveness HTTP probe that pings the whatismyvip() HTTP endpoint.

The host kubelet will restart the pod if you get any unexpected HTTP status codes.

define a liveness HTTP request

Otherwise if what you mean by forcing a particular replica is that you wish to direct your request into a specific pod from outside the cluster, then perhaps a custom solution might be better. Each see if 2 X pods on each node might have a clusterIP service fronting them. Then use a loadbalanced service fronting a custom app that proxies your request for a specific replica or set of pods based on your request.

Eg a URL query string parameter that targets clusterIP service A, B, C, or D.

https://customrouterapp/whatismyvip?replicaset=B

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM