Container-to-container communication

In this scenario, we would focus on the communications between containers within single Pod:

  1. Let's create two containers in one Pod: a nginx web application and a CentOS, which checks port 80 on localhost:
// configuration file of creating two containers within a pod$ cat two-container-pod.yamlapiVersion: v1kind: Podmetadata:  name: two-containerspec:  containers:    - name: web      image: nginx      ports:        - containerPort: 80          hostPort: 80    - name: centos      image: centos      command: ["/bin/sh", "-c", "while : ;do curl http://localhost:80/; sleep 30; done"]// create the pod$ kubectl create -f two-container-pod.yamlpod "two-container" created// check the status of the newly-created Pod$ kubectl get pod two-containerNAME READY ...

Get Kubernetes Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.