Lab 4 - Multi-Container Pods¶
30 min Intermediate
Problem¶
The millennium-falcon service has already been packaged into a container image, but it comes with a special requirement:
- The legacy app is hard-coded to serve only on port
8989, but the team wants to reach it on the standard web port8080.
Your task is to build a Pod that runs the legacy container and uses the ambassador pattern to expose it on port 8080. The ambassador is a second container in the same Pod that proxies traffic to the legacy app. Containers in a Pod share a network namespace, so the ambassador can reach the app on 127.0.0.1.
The Pod must meet these requirements:
- The Pod is named
vader-service. - It has a container named
millennium-falconthat runs the legacy imageregistry.k8s.io/e2e-test-images/agnhost:2.56with the argumentsnetexecand--http-port=8989. - It has an ambassador container named
nginx-ambassadorthat runs thequay.io/nginx/nginx-unprivileged:1.29image and proxies incoming traffic on port8080to the legacy service on port8989. - Port
8080is exposed as acontainerPorton the ambassador. You don't need to expose port8989. -
The nginx configuration is stored in a ConfigMap named
vader-service-ambassador-config, under the keydefault.conf, with this content: -
The ConfigMap is mounted into the ambassador container as a volume at
/etc/nginx/conf.d, so the file ends up at/etc/nginx/conf.d/default.conf.
Setup¶
Verification¶
Test the service from inside the cluster through port 8080. Create a client Pod to send requests from:
apiVersion: v1
kind: Pod
metadata:
name: client
spec:
containers:
- name: client
image: registry.access.redhat.com/ubi9/ubi-minimal
command: ["sleep", "infinity"]
Call vader-service on port 8080 from the client Pod:
oc exec client -- curl -s "$(oc get pod vader-service -o jsonpath='{.status.podIP}'):8080/echo?msg=The+hyperdrive+needs+repair"
If the ambassador is working, the legacy app echoes back The hyperdrive needs repair.
Cleanup¶
Relevant documentation: