Networking between pods
In part 1 we managed to setup networking configuration to enable routing traffic from outside of the cluster to a container inside a pod. In Part 2 we'll focus on communication between applications.
Kubernetes includes a DNS service so communication between pods and containers in Kubernetes is as much of a challenge as it was with containers in docker-compose. Containers in a pod share the network. As such every other container inside a pod is accessible from
localhost. For communication between Pods a Service is used as they expose the Pods as a network service.
The following creates a cluster-internal IP which will enable other pods in the cluster to access the port 8080 of "example" application from http://example-service. ClusterIP is the default type for a Service.
apiVersion: v1 kind: Service metadata: name: example-service spec: type: ClusterIP selector: app: example ports: - name: http protocol: TCP port: 80 targetPort: 8080
Alternatively each Pod has an IP created by Kubernetes.