Inter-container communication

Reference link

1. ConfigMap content

config-map.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: mc3-nginx-conf
data:
  nginx.conf: |-
    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events {
        worker_connections  1024;
    }

    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;

        sendfile        on;
        keepalive_timeout  65;

        upstream webapp {
            server 127.0.0.1:5000;
        }

        server {
            listen 80;

            location / {
                proxy_pass         http://webapp;
                proxy_redirect     off;
            }
        }
    }

2. Create a multi-container application as follows

  • has simple web-app container

  • has an nginx container

inter-container.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mc3
  labels:
    app: mc3
spec:
  containers:
  - name: webapp
    image: training/webapp
  - name: nginx
    image: nginx:alpine
    ports:
    - containerPort: 80
    volumeMounts:
    - name: nginx-proxy-config
      mountPath: /etc/nginx/nginx.conf
      subPath: nginx.conf
  volumes:
  - name: nginx-proxy-config
    configMap:
      name: mc3-nginx-conf
  • create the pod

  • expose the service mc3 as follows

hadoop@k8s-00:~$ kubectl expose pod mc3 --type=NodePort --port=80
service "mc3" exposed
  • describe the service as follows
hadoop@k8s-00:~$ kubectl describe service mc3
Name:                     mc3
Namespace:                default
Labels:                   app=mc3
Annotations:              <none>
Selector:                 app=mc3
Type:                     NodePort
IP:                       10.111.40.221
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30023/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
  • from the above, get the port on the node that is forwarded to the pod

  • in out case it is 30023

  • use curl to access the web service (didn't work)

curl localhost:30023

results matching ""

    No results matching ""