This tutorial will cover steps to create a pod with nginx container and ubuntu containers with shared volume. Both containers will have the same IP and we can get shell on both of these.
- Create config file multi-pod.yml
apiVersion: v1 kind: Pod metadata: name: multi-pod spec: restartPolicy: Never volumes: - name: shared-data emptyDir: {} containers: - name: nginx-container image: nginx volumeMounts: - name: shared-data mountPath: /usr/share/nginx/html - name: ubuntu-container image: ubuntu volumeMounts: - name: shared-data mountPath: /pod-data command: ["/bin/sh"] args: ["-c", "echo Hello, World!!! > /pod-data/index.html && sleep 3600"]
We need to add the sleep command to ensure container does not finish running. - Create the pod
kubectl apply -f multi-pod.yml
- Get a shell to the nginx container
kubectl exec -it multi-pod -c nginx-container -- /bin/bash
- Install ifconfig and curl
apt-get update -y
apt-get install -y net-tools
apt-get install -y curl - Run ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.1.0.45 netmask 255.255.0.0 broadcast 10.1.255.255 ether 4a:16:6c:5f:36:86 txqueuelen 0 (Ethernet) RX packets 24703 bytes 36774193 (35.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 13083 bytes 717718 (700.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 24 bytes 1930 (1.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 24 bytes 1930 (1.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- Run curl
curl localhost
orcurl 10.1.0.45
You should see:Hello, World!!!
- Get a shell to the ubuntu container
kubectl exec -it multi-pod -c ubuntu-container -- /bin/bash
- Repeat above steps to install curl and ifconfig. Notice that the IP address is same as above container and curl works on localhost in same way.