Networking between two pods

0 votes

I'm still a noob in kubernetes. it would be great if someone gave me an example with yaml file for the following requirement:

  • I need two pods running 
  • One as backend and the other as frontend
  • I need a way to network between them
Sep 24, 2018 in Kubernetes by Hannah
• 18,570 points
408 views

1 answer to this question.

0 votes

Define service resources for both your front-end and back-end application, this allows communication between them which is required for networking.

apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  selector:
    app: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

Next you define the ingress resources since both the services need access from outside the cluster.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: frontend
spec:      
  rules:
  - host: www.your-application.example
    http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: backend
spec:      
  rules:
  - host: api.your-application.example
    http:
      paths:
      - path: /
        backend:
          serviceName: backend
          servicePort: 80
answered Sep 24, 2018 by Kalgi
• 52,360 points

Related Questions In Kubernetes

+1 vote
1 answer

How to use a Volume to communicate between two Containers running in the same Kubernetes-Pod?

Create a Pod that runs two Containers Create a ...READ MORE

answered Jul 23, 2019 in Kubernetes by Sirajul
• 59,230 points
2,366 views
0 votes
1 answer

deleting pods using kubernetes replication controller

The pods which are managed by ReplicationController ...READ MORE

answered Jul 24, 2018 in Kubernetes by DareDev
• 6,890 points
873 views
0 votes
1 answer

Getting the pod's ip address for the container inside of it

You can make sure that the replication ...READ MORE

answered Aug 24, 2018 in Kubernetes by DareDev
• 6,890 points
2,393 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
14,614 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,360 points

reshown Apr 12, 2019 by Kalgi 6,106 views
0 votes
1 answer

Is possible to have same k8s service for multiple pods?

Reserve a static IP and then assign ...READ MORE

answered Jul 20, 2018 in Kubernetes by Kalgi
• 52,360 points
2,822 views
0 votes
1 answer

Pods IP address from inside a container in the pod

Make sure that your pod yaml file ...READ MORE

answered Aug 29, 2018 in Kubernetes by Kalgi
• 52,360 points
2,131 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP