Uploaded image for project: 'National Data Service'
  1. National Data Service
  2. NDS-82 Clowder on Kubernetes
  3. NDS-91

Executing kubectl from inside of ndsdev container

XMLWordPrintableJSON

      Step to Recreate:
      1.) Checkout the code and run necessary container (ndsdev):

      git clone https://github.com/bodom0015/nds-labs
      cd nds-labs/
      git fetch --all
      git checkout v2plusClowder
      docker create --name=NDSSRC -v 'pwd`:/nds/src ubuntu:wily
      docker build -t ndsdev -f ./devtools/ndsdev/Dockerfile.ndsdev .
      docker run -i -t --name=NDSDEV --volumes-from=NDSSRC --privileged --rm -v /var/run/docker.sock:/var/run/docker.sock ndsdev /bin/bash

      2.) Now that we are inside of ndsdev, start up a local Kubernetes using the helper script:

      . ./devtools/ndsdev/kubeUpLocal.sh <desired_ip>

      3.) Verify state / output:
      Running a docker ps shows us that the main pieces of our cluster started just as we expected.

      Running a kubectl command from the host OS yields what we expect:

      core@lambert-02 ~ $ kubectl get nodes
      NAME        LABELS                             STATUS    AGE
      127.0.0.1   kubernetes.io/hostname=127.0.0.1   Ready     27s

      However, attempting to execute kubectl from inside of the ndsdev container yields:

      root@308c0d207447:/nds/src# kubectl get nodes
      error: couldn't read version from server: Get http://localhost:8080/api: dial tcp 127.0.0.1:8080: connection refused

      Expected Behavior:
      kubectl should work inside of the container to allow for ndsdev to encapsulate the entire dev environment and workflow, including the environment necessary to test your changes.

      Why is this happening?
      When we run the ndsdev container, we tell it to run using the host's docker daemon. When ndsdev then goes to start Kubernetes, the cluster is also running on the host's docker daemon. Thus, kubectl works fine from the host OS (as localhost resolves correctly to the node ip of 127.0.0.1)

      What I Have Tried:
      1.) Specify to Kubernetes that it will NOT be running on localhost, and to use the docker0 ip instead:

      • . ./devtools/ndsdev/kubeUpLocal.sh 10.0.1.1

      2.) Specify to ndsdev to resolve any address conflicts using 10.0.1.1's /etc/resolv.conf

      • docker run -i -t --name=NDSDEV --volumes-from=NDSSRC --privileged --rm -v /var/run/docker.sock:/var/run/docker.sock --dns=10.0.1.1 ndsdev /bin/bash

      3.) Manually try to hack around the DNS (due to the nature of localhost, this will likely never work):

      • docker run -i -t --name=NDSDEV --volumes-from=NDSSRC --privileged --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc/resolv.conf:/etc/resolv.conf ndsdev /bin/bash

      Perhaps we simply need to specify to docker and/or Kubernetes that its IP should not be localhost, and instead explicitly provide it with an appropriate IP matching that of the node/cluster? It is possible that the step I have tried above were either incorrect or incomplete. Maybe we need to use a combination of these tactics?

              raila David Raila
              lambert8 Sara Lambert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: