How do I expose Docker a Docker port via Kubernetes in Google Cloud?

I am trying to wrap my head around provisioning Docker instances in Kubernetes on Google Cloud. I have build a replica controller that specifies a single pod and defined a port to be exposed, but it is not being exposed.

Here is my containers.yaml:

  • In Docker, do I need to publish ports if I set network to host?
  • How to avoid typing the container id when using docker commit?
  • Installing Oracle database in docker container
  • Magento2 Docker Devbox Exception
  • What is the difference between Docker Host and Container
  • Google cloud container engine vs normal vm
  • apiVersion: v1
    kind: ReplicationController
      name: postgres
      replicas: 1
        app: postgres
          name: postgres
            app: postgres
          - name: postgres
                containerPort: 5432
                name: postgres
                protocol: TCP

    Here is the result of docker ps while running as root in my compute engine instance that is running this pod:

    root@gke-legal-data-6fddb637-node-49l5:/home/eric# docker ps
    CONTAINER ID        IMAGE                                       COMMAND                CREATED              STATUS              PORTS               NAMES
    c16b7e0071f4          "/docker-entrypoint.   About a minute ago   Up About a minute                       k8s_postgres.82df2fa1_postgres-7wd6n_default_4e36d84b-2c1f-11e5-8f6f-42010af0664d_2a996ec3
    036f8d6375bc        "/pause"               About a minute ago   Up About a minute                       k8s_POD.e4cc795_postgres-7wd6n_default_4e36d84b-2c1f-11e5-8f6f-42010af0664d_8b058463
    14c6331ce91f   "/heapster --source=   3 minutes ago        Up 3 minutes                            k8s_heapster.bb306f05_monitoring-heapster-v5-p0orx_kube-system_983e585e-2bd7-11e5-8f6f-42010af0664d_b8b0aff1
    8ab049b45e57        "/pause"               6 hours ago          Up 6 hours                              tender_rosalind
    03c9810efd2d    "\"/bin/sh -c '/usr/   8 hours ago          Up 8 hours                              k8s_fluentd-cloud-logging.7721935b_fluentd-cloud-logging-gke-legal-data-6fddb637-node-49l5_kube-system_d0feac1ad02da9e97c4bf67970ece7a1_520ad44a
    8ad81f1eb559        "/pause"               8 hours ago          Up 8 hours                              k8s_POD.e4cc795_monitoring-heapster-v5-p0orx_kube-system_983e585e-2bd7-11e5-8f6f-42010af0664d_d321075c
    931e38c13e91        "/pause"               8 hours ago          Up 8 hours                              k8s_POD.e4cc795_fluentd-cloud-logging-gke-legal-data-6fddb637-node-49l5_kube-system_d0feac1ad02da9e97c4bf67970ece7a1_69d90d4f

    You can see that there are no ports exposed. Why isn’t my postgres (port 5432) exposed?

  • How to detect fully interactive shell in bash from docker?
  • Docker: Where to store version of multiple images for docker-compose?
  • Trying docker in docker getting TCP connection refused error
  • How to restrict access to path in Docker container?
  • Can several nodes access mounted docker containers
  • docker: is it possible to run containers from an other container?
  • 2 Solutions collect form web for “How do I expose Docker a Docker port via Kubernetes in Google Cloud?”

    Each pod in kubernetes is given its own IP address on the cluster’s private network. The port that your postgres container has open is on that IP address, not directly on the host VM’s IP.

    If you run kubectl get pod postgres, it should return the pod’s IP address, which you should then be able to use to reach postgres from within the cluster.

    Note that using a service is a common way to give a DNS name to a pod or to make a group of replicated pods all reachable at the same address.

    If you are not exposing the port externally using a service.yml then you can forward the port to yourself using this method.

    Open up Kubernetes, click on Pods, collapse the menu if you can’t read the pod names and click the pod you want to forward. Copy the name of the pod and insert it into this command.

    kubectl port-forward <your pod name> <port number>


    kubectl port-forward potato-dks2ko3 8080
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.