<p>Background : I am trying to learn and experiment a bit on docker and kubernetes in a "development/localhost" environment, that I could later replicate "for real" on some Cloud. But I'm running low on everything (disk capacity, memory, etc.) on my laptop. So I figured out "why not develop from the cloud ?"</p>

<p>I know AWS has some Kubernetes service, but if my understanding is correct, this is mostly to deploy already well configured stacks, and it is not very suited for the development of the stack configuration itself. </p>

<p>After searching a bit, I found out about Minikube, that helps us experiment our configs by running kubernetes deployments on a single machine. <strong>I'd like to setup a kubernetes + Minikube (or equivalent) development environment from an EC2 instance (ideally running Amazon Linux 2 OS).</strong></p>

<p>I'm having a hard time figuring out </p>

<ul>
<li><strong>Is it actually possible to setup Minikube on EC2 ?</strong></li>
<li>(If yes), how do I do it ? I tried following <a href="https://stackoverflow.com/a/46756411/2832282">this answer</a> but I'm getting stuck at registering the Virtualbox Repo and downloading Virtualbox command line tools</li>
</ul>

<p>Heres how to do it</p>

<p>Start an ec2 instance with 8gb of ram and a public ip, ensure you can ssh to this box in the normal ways. Ensure its an unbuntu instance (I'm using 16.04).</p>

<p>once ssh'd into the instance run the following to update and install docker</p>

<pre><code>sudo -i
apt-get update -y &amp;&amp; apt-get install docker.io
</code></pre>

<p>Install minikube</p>

<pre><code>curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 &amp;&amp; chmod +x minikube &amp;&amp; sudo mv minikube /usr/local/bin/
</code></pre>

<p>Install kube cli </p>

<pre><code>curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl &amp;&amp; chmod +x kubectl &amp;&amp; sudo mv kubectl /usr/local/bin/
</code></pre>

<p>now verify the version just to make sure you can see it</p>

<pre><code>/usr/local/bin/minikube version
</code></pre>

<p>Add autocompletion to the current shell with</p>

<pre><code>source &lt;(kubectl completion bash)
</code></pre>

<p>Start the cluster with this (note the no vm driver line)</p>

<pre><code>/usr/local/bin/minikube start --vm-driver=none
</code></pre>

<p>Check its up and running with this:</p>

<pre><code>/usr/local/bin/minikube status
</code></pre>

<p>right that should have you a basic cluster running with no extra nodes :)</p>

<p>If you want a nice dashboard do the following (I am using windows here making use of wsl on windows 10, you can do this on mac or linux if you like but the steps are slightly different but as long as you can follow basic steps like setting variables you will be cool)</p>

<p>In order to see the gui on your local box you are going to need to run a dashboard and to do other useful stuff run kubectl locally</p>

<p><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/" rel="nofollow noreferrer">Please follow this to install kubectl locally</a></p>

<p>On windows you can use chocolatey like so:</p>

<pre><code>choco install kubernetes-cli
</code></pre>

<p>Now download your admin.conf file from the ec2 instance using scp this is located in /etc/kubernetes.</p>

<p>Now set a local variable called <code>KUBECONFIG</code> and point to the file you just downloaded.</p>

<p>Go on to the ec2 instance and use this to install a dashboard.</p>

<pre><code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/alternative/kubernetes-dashboard-arm.yaml
</code></pre>

<p>This dashboard is a dev dashboard do not use this in production :)</p>

<p>run the following command to find out what ip address the dashboard is running on</p>

<pre><code>/usr/local/bin/kubectl get svc --namespace kube-system
</code></pre>

<p>output should look a bit like this:</p>

<pre><code>root@ip-172-31-39-236:~# /usr/local/bin/kubectl get svc --namespace kube-system
NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
kube-dns               ClusterIP   10.96.0.10      &lt;none&gt;        53/UDP,53/TCP   49m
kubernetes-dashboard   NodePort    10.109.248.81   &lt;none&gt;        80:30000/TCP    49m
</code></pre>

<p>now run this on your localbox to tunnel to the dashboard from the local machine</p>

<pre><code>ssh -i ~/.ssh/keyfile.pem -L 8080:10.109.248.81:80 ubuntu@ec2-i-changed-this-for-this-post.eu-west-1.compute.amazonaws.com
</code></pre>

<p>now open a web browser at:</p>

<pre><code>http://localhost:8080 
</code></pre>

<p>and you should now be able to see the dashboard. Which looks like this:</p>

<p><a href="https://i.stack.imgur.com/L0QJZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L0QJZ.png" alt="enter image description here"></a></p>

<p>Sorry the post is so long but its pretty involved. also please note this is really only a dev machine if you are going to need a prod instance you need to do this with better security and probably not run stuff as root :)</p>

<p>One other thing, you may note kubectl locally isn't being used in this guide you can use it to hit the remote api if you use (locally)</p>

<pre><code>kubectl proxy
</code></pre>

<p>There is a guide on this on kubernetes homepage <a href="https://kubernetes.io/docs/tasks/access-kubernetes-api/http-proxy-access-api/" rel="nofollow noreferrer">here</a>
Also note the admin.conf probably has localhost as the server address, it needs to be the address of the ec2 instance and you'll need to make sure the port is accessible from your ip in your security group for the ec2 instance. </p>

<p>If you curl or browser to <code>http://localhost:8001/api</code> you should see this or something like it :)</p>

<pre><code>{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "192.168.4.60:6443"
    }
  ]
}
</code></pre>
