How did the proxy know to connect to port 5000 on the container?

When you ran a container, Kubernetes did not magically know what TCP ports your code is listening on. When we created this deployment using the kubectl run command, we added the --port=5000 option at the end of that command. That was used by Kubernetes to know that the program should be listening on port 5000 for HTTP traffic. If you look back at the output from the kubectl get deployment -o json command, you will see a section in there under the key containers that includes the image we provided, the name of the deployment, and a data structure indicating a default port for accessing the container: 5000. If we had not provided the additional details, the proxy would have assumed we wanted to access the container at port 80. Since nothing is running on port 80 with our development container, you would have seen an error akin to the following:

Error: 'dial tcp 172.17.0.4:80: getsockopt: connection refused'
Trying to reach: 'http://172.17.0.4/'