title: How to run kubectl commands inside a container?
body: <p>In a container inside a pod, how can I run a command using kubectl? For example, if i need to do something like this inside a container: </p>
  
  <blockquote>
    <p>kubectl get pods</p>
  </blockquote>
  
  <p>I have tried this : In my dockerfile, I have these commands : </p>
  
  <pre><code>RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  RUN chmod +x ./kubectl
  RUN sudo mv ./kubectl /usr/local/bin/kubectl
  </code></pre>
  
  <blockquote>
    <p>EDIT : I was trying the OSX file, I have corrected it to the linux binary file. (corrected by @svenwltr</p>
  </blockquote>
  
  <p>While creating the docker file, this is successful, but when I run the kubectl get pods inside a container, </p>
  
  <pre><code>kubectl get pods
  </code></pre>
  
  <p>I get this error :</p>
  
  <blockquote>
    <p>The connection to the server : was refused - did you specify the right host or port?    </p>
  </blockquote>
  
  <p>When I was deploying locally, I was encountering this error if my docker-machine was not running, but inside a container how can a docker-machine be running? </p>
  
  <p>Locally, I get around this error by running the following commands:
  (dev is the name of the docker-machine)</p>
  
  <pre><code>docker-machine env dev
  eval $(docker-machine env dev)
  </code></pre>
  
  <p>Can someone please tell me what is it that I need to do?</p>