How do I make one kubernetes service talking to other kubernetes service?










0














I have two services (client and server) both of types of load balancer. I would like to make the client service talking to server service. How do I do programmatically (via yaml file etc).



More explicitly client runs a python code in which it needs access to server's external ip. However I only know server service name not external ip.



of course one way to solve this issue is to launch server first and get the external ip and add it to client's yaml file. I am looking for solution like accessing external ip by just knowing the service name.



Client and server resides in the same kubernetes cluster.



Client.yaml Client runs a web server and if someone hits the url advertised by web server demo.py should make a call to the server's service. I was thinking of a way to get the server's external-ip programmatically here, however I am open for suggestions.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name:client-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: client
spec:
containers:
- name: client-container
image: client_image:latest
command:
- "python"
- "/root/demo.py"
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: client-service
name: client-service
spec:
ports:
- port: 5000
targetPort: 5000
selector:
app: inception-client
type: LoadBalancer


Server.yaml: It exposes a service at port 9000, which client should call.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: server
spec:
containers:
- name: server-container
image: server_image:latest
command:
- <Command to start a server which listens on port 9000>
ports:
- containerPort: 9000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: server-service
name: server-service
spec:
ports:
- port: 9000
targetPort: 9000
selector:
app: server
type: LoadBalancer









share|improve this question























  • Does your 'server' service needs to be accesible from anywhere other than 'client' service or is your 'server' service talking to anyone else other than your 'client' service ?
    – murarisumit
    Nov 13 at 5:57










  • Server's service is also getting accessed from others as well like via CLI etc.
    – rgaut
    Nov 13 at 7:12










  • I meant to ask that if that 'server' service is used out of cluster too, because if it isn't we don't need service type load balancer for it and we can directly access it via service-name as mentioned by others in answers.
    – murarisumit
    Nov 13 at 7:15






  • 1




    Yes you can do directly ClusterIP:9000, or service-name:9000, from 'client' service. if both the services are in different namespace then 'service-name.namespace:9000'
    – murarisumit
    Nov 14 at 0:48






  • 1




    Even if service-type is 'NodePort' or 'Loadbalancer', ^comment i.e. 'server-service:9000' will also work
    – murarisumit
    Nov 14 at 0:51
















0














I have two services (client and server) both of types of load balancer. I would like to make the client service talking to server service. How do I do programmatically (via yaml file etc).



More explicitly client runs a python code in which it needs access to server's external ip. However I only know server service name not external ip.



of course one way to solve this issue is to launch server first and get the external ip and add it to client's yaml file. I am looking for solution like accessing external ip by just knowing the service name.



Client and server resides in the same kubernetes cluster.



Client.yaml Client runs a web server and if someone hits the url advertised by web server demo.py should make a call to the server's service. I was thinking of a way to get the server's external-ip programmatically here, however I am open for suggestions.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name:client-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: client
spec:
containers:
- name: client-container
image: client_image:latest
command:
- "python"
- "/root/demo.py"
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: client-service
name: client-service
spec:
ports:
- port: 5000
targetPort: 5000
selector:
app: inception-client
type: LoadBalancer


Server.yaml: It exposes a service at port 9000, which client should call.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: server
spec:
containers:
- name: server-container
image: server_image:latest
command:
- <Command to start a server which listens on port 9000>
ports:
- containerPort: 9000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: server-service
name: server-service
spec:
ports:
- port: 9000
targetPort: 9000
selector:
app: server
type: LoadBalancer









share|improve this question























  • Does your 'server' service needs to be accesible from anywhere other than 'client' service or is your 'server' service talking to anyone else other than your 'client' service ?
    – murarisumit
    Nov 13 at 5:57










  • Server's service is also getting accessed from others as well like via CLI etc.
    – rgaut
    Nov 13 at 7:12










  • I meant to ask that if that 'server' service is used out of cluster too, because if it isn't we don't need service type load balancer for it and we can directly access it via service-name as mentioned by others in answers.
    – murarisumit
    Nov 13 at 7:15






  • 1




    Yes you can do directly ClusterIP:9000, or service-name:9000, from 'client' service. if both the services are in different namespace then 'service-name.namespace:9000'
    – murarisumit
    Nov 14 at 0:48






  • 1




    Even if service-type is 'NodePort' or 'Loadbalancer', ^comment i.e. 'server-service:9000' will also work
    – murarisumit
    Nov 14 at 0:51














0












0








0







I have two services (client and server) both of types of load balancer. I would like to make the client service talking to server service. How do I do programmatically (via yaml file etc).



More explicitly client runs a python code in which it needs access to server's external ip. However I only know server service name not external ip.



of course one way to solve this issue is to launch server first and get the external ip and add it to client's yaml file. I am looking for solution like accessing external ip by just knowing the service name.



Client and server resides in the same kubernetes cluster.



Client.yaml Client runs a web server and if someone hits the url advertised by web server demo.py should make a call to the server's service. I was thinking of a way to get the server's external-ip programmatically here, however I am open for suggestions.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name:client-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: client
spec:
containers:
- name: client-container
image: client_image:latest
command:
- "python"
- "/root/demo.py"
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: client-service
name: client-service
spec:
ports:
- port: 5000
targetPort: 5000
selector:
app: inception-client
type: LoadBalancer


Server.yaml: It exposes a service at port 9000, which client should call.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: server
spec:
containers:
- name: server-container
image: server_image:latest
command:
- <Command to start a server which listens on port 9000>
ports:
- containerPort: 9000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: server-service
name: server-service
spec:
ports:
- port: 9000
targetPort: 9000
selector:
app: server
type: LoadBalancer









share|improve this question















I have two services (client and server) both of types of load balancer. I would like to make the client service talking to server service. How do I do programmatically (via yaml file etc).



More explicitly client runs a python code in which it needs access to server's external ip. However I only know server service name not external ip.



of course one way to solve this issue is to launch server first and get the external ip and add it to client's yaml file. I am looking for solution like accessing external ip by just knowing the service name.



Client and server resides in the same kubernetes cluster.



Client.yaml Client runs a web server and if someone hits the url advertised by web server demo.py should make a call to the server's service. I was thinking of a way to get the server's external-ip programmatically here, however I am open for suggestions.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name:client-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: client
spec:
containers:
- name: client-container
image: client_image:latest
command:
- "python"
- "/root/demo.py"
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: client-service
name: client-service
spec:
ports:
- port: 5000
targetPort: 5000
selector:
app: inception-client
type: LoadBalancer


Server.yaml: It exposes a service at port 9000, which client should call.



apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: server-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: server
spec:
containers:
- name: server-container
image: server_image:latest
command:
- <Command to start a server which listens on port 9000>
ports:
- containerPort: 9000
---
apiVersion: v1
kind: Service
metadata:
labels:
run: server-service
name: server-service
spec:
ports:
- port: 9000
targetPort: 9000
selector:
app: server
type: LoadBalancer






kubernetes kubernetes-service






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 1:13

























asked Nov 12 at 8:04









rgaut

8011018




8011018











  • Does your 'server' service needs to be accesible from anywhere other than 'client' service or is your 'server' service talking to anyone else other than your 'client' service ?
    – murarisumit
    Nov 13 at 5:57










  • Server's service is also getting accessed from others as well like via CLI etc.
    – rgaut
    Nov 13 at 7:12










  • I meant to ask that if that 'server' service is used out of cluster too, because if it isn't we don't need service type load balancer for it and we can directly access it via service-name as mentioned by others in answers.
    – murarisumit
    Nov 13 at 7:15






  • 1




    Yes you can do directly ClusterIP:9000, or service-name:9000, from 'client' service. if both the services are in different namespace then 'service-name.namespace:9000'
    – murarisumit
    Nov 14 at 0:48






  • 1




    Even if service-type is 'NodePort' or 'Loadbalancer', ^comment i.e. 'server-service:9000' will also work
    – murarisumit
    Nov 14 at 0:51

















  • Does your 'server' service needs to be accesible from anywhere other than 'client' service or is your 'server' service talking to anyone else other than your 'client' service ?
    – murarisumit
    Nov 13 at 5:57










  • Server's service is also getting accessed from others as well like via CLI etc.
    – rgaut
    Nov 13 at 7:12










  • I meant to ask that if that 'server' service is used out of cluster too, because if it isn't we don't need service type load balancer for it and we can directly access it via service-name as mentioned by others in answers.
    – murarisumit
    Nov 13 at 7:15






  • 1




    Yes you can do directly ClusterIP:9000, or service-name:9000, from 'client' service. if both the services are in different namespace then 'service-name.namespace:9000'
    – murarisumit
    Nov 14 at 0:48






  • 1




    Even if service-type is 'NodePort' or 'Loadbalancer', ^comment i.e. 'server-service:9000' will also work
    – murarisumit
    Nov 14 at 0:51
















Does your 'server' service needs to be accesible from anywhere other than 'client' service or is your 'server' service talking to anyone else other than your 'client' service ?
– murarisumit
Nov 13 at 5:57




Does your 'server' service needs to be accesible from anywhere other than 'client' service or is your 'server' service talking to anyone else other than your 'client' service ?
– murarisumit
Nov 13 at 5:57












Server's service is also getting accessed from others as well like via CLI etc.
– rgaut
Nov 13 at 7:12




Server's service is also getting accessed from others as well like via CLI etc.
– rgaut
Nov 13 at 7:12












I meant to ask that if that 'server' service is used out of cluster too, because if it isn't we don't need service type load balancer for it and we can directly access it via service-name as mentioned by others in answers.
– murarisumit
Nov 13 at 7:15




I meant to ask that if that 'server' service is used out of cluster too, because if it isn't we don't need service type load balancer for it and we can directly access it via service-name as mentioned by others in answers.
– murarisumit
Nov 13 at 7:15




1




1




Yes you can do directly ClusterIP:9000, or service-name:9000, from 'client' service. if both the services are in different namespace then 'service-name.namespace:9000'
– murarisumit
Nov 14 at 0:48




Yes you can do directly ClusterIP:9000, or service-name:9000, from 'client' service. if both the services are in different namespace then 'service-name.namespace:9000'
– murarisumit
Nov 14 at 0:48




1




1




Even if service-type is 'NodePort' or 'Loadbalancer', ^comment i.e. 'server-service:9000' will also work
– murarisumit
Nov 14 at 0:51





Even if service-type is 'NodePort' or 'Loadbalancer', ^comment i.e. 'server-service:9000' will also work
– murarisumit
Nov 14 at 0:51













2 Answers
2






active

oldest

votes


















2














The client only needs to know the kubernetes Service name linked to the server. Kubernetes will handle the routing to the desired server pod. Specifying a load balancer also implicitly creates a clusterip. Which your client python application can use.



You can provide in your client code a readiness probe that checks if the server is up, that way you can be sure that when the server is ready, the client can also start taking requests.






share|improve this answer




















  • Can you give one example? I am adding my code.
    – rgaut
    Nov 13 at 1:07










  • Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
    – Bal Chua
    Nov 13 at 11:48


















0














As you have not specified on where the servers reside, lets consider both cases.



Case 1: Services are within the same cluster




Use service name in place of host ip address. kube-proxy converts the service name to ip address(internal).




Case 2: Services are not in the same cluster.




Establishing a connection between them requires an external IP address. One alternative approach is to write a bash script.
Write a bash script to get the ip address programatically and store it in a variable. Substitute this variable within the server yaml file.







share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257982%2fhow-do-i-make-one-kubernetes-service-talking-to-other-kubernetes-service%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The client only needs to know the kubernetes Service name linked to the server. Kubernetes will handle the routing to the desired server pod. Specifying a load balancer also implicitly creates a clusterip. Which your client python application can use.



    You can provide in your client code a readiness probe that checks if the server is up, that way you can be sure that when the server is ready, the client can also start taking requests.






    share|improve this answer




















    • Can you give one example? I am adding my code.
      – rgaut
      Nov 13 at 1:07










    • Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
      – Bal Chua
      Nov 13 at 11:48















    2














    The client only needs to know the kubernetes Service name linked to the server. Kubernetes will handle the routing to the desired server pod. Specifying a load balancer also implicitly creates a clusterip. Which your client python application can use.



    You can provide in your client code a readiness probe that checks if the server is up, that way you can be sure that when the server is ready, the client can also start taking requests.






    share|improve this answer




















    • Can you give one example? I am adding my code.
      – rgaut
      Nov 13 at 1:07










    • Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
      – Bal Chua
      Nov 13 at 11:48













    2












    2








    2






    The client only needs to know the kubernetes Service name linked to the server. Kubernetes will handle the routing to the desired server pod. Specifying a load balancer also implicitly creates a clusterip. Which your client python application can use.



    You can provide in your client code a readiness probe that checks if the server is up, that way you can be sure that when the server is ready, the client can also start taking requests.






    share|improve this answer












    The client only needs to know the kubernetes Service name linked to the server. Kubernetes will handle the routing to the desired server pod. Specifying a load balancer also implicitly creates a clusterip. Which your client python application can use.



    You can provide in your client code a readiness probe that checks if the server is up, that way you can be sure that when the server is ready, the client can also start taking requests.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 12 at 11:18









    Bal Chua

    52215




    52215











    • Can you give one example? I am adding my code.
      – rgaut
      Nov 13 at 1:07










    • Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
      – Bal Chua
      Nov 13 at 11:48
















    • Can you give one example? I am adding my code.
      – rgaut
      Nov 13 at 1:07










    • Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
      – Bal Chua
      Nov 13 at 11:48















    Can you give one example? I am adding my code.
    – rgaut
    Nov 13 at 1:07




    Can you give one example? I am adding my code.
    – rgaut
    Nov 13 at 1:07












    Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
    – Bal Chua
    Nov 13 at 11:48




    Setting up livenessProbe and readinessProbe is well documented in kubernetes kubernetes.io/docs/tasks/configure-pod-container/…. How your application do inside those is really up to you.
    – Bal Chua
    Nov 13 at 11:48













    0














    As you have not specified on where the servers reside, lets consider both cases.



    Case 1: Services are within the same cluster




    Use service name in place of host ip address. kube-proxy converts the service name to ip address(internal).




    Case 2: Services are not in the same cluster.




    Establishing a connection between them requires an external IP address. One alternative approach is to write a bash script.
    Write a bash script to get the ip address programatically and store it in a variable. Substitute this variable within the server yaml file.







    share|improve this answer

























      0














      As you have not specified on where the servers reside, lets consider both cases.



      Case 1: Services are within the same cluster




      Use service name in place of host ip address. kube-proxy converts the service name to ip address(internal).




      Case 2: Services are not in the same cluster.




      Establishing a connection between them requires an external IP address. One alternative approach is to write a bash script.
      Write a bash script to get the ip address programatically and store it in a variable. Substitute this variable within the server yaml file.







      share|improve this answer























        0












        0








        0






        As you have not specified on where the servers reside, lets consider both cases.



        Case 1: Services are within the same cluster




        Use service name in place of host ip address. kube-proxy converts the service name to ip address(internal).




        Case 2: Services are not in the same cluster.




        Establishing a connection between them requires an external IP address. One alternative approach is to write a bash script.
        Write a bash script to get the ip address programatically and store it in a variable. Substitute this variable within the server yaml file.







        share|improve this answer












        As you have not specified on where the servers reside, lets consider both cases.



        Case 1: Services are within the same cluster




        Use service name in place of host ip address. kube-proxy converts the service name to ip address(internal).




        Case 2: Services are not in the same cluster.




        Establishing a connection between them requires an external IP address. One alternative approach is to write a bash script.
        Write a bash script to get the ip address programatically and store it in a variable. Substitute this variable within the server yaml file.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 11:20









        Rushil Basappa

        343




        343



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257982%2fhow-do-i-make-one-kubernetes-service-talking-to-other-kubernetes-service%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands