├── README.md └── kube-init.sh /README.md: -------------------------------------------------------------------------------- 1 | # kube-init 2 | 3 | Easiest way to deploy a Kubernetes Cluster to learn Kubernetes 4 | 5 | ### Deploy the Cluster 6 | 7 | 1. Create a Ubuntu 64 Server/VM from your favourite cloud provider 8 | 2. Then apply: `wget -qO- https://git.io/veKlu | sudo sh` 9 | 3. Now you've a standalone Kubernetes cluster running inside your server 10 | 11 | ### Configure Network Access (optional) 12 | Now we need to configure your local machine to access the Kubernetes network. 13 | 14 | 1. Let's create a SOCKS proxy server with this command: `ssh -D 8082 root@your-server-ip` 15 | 2. Then configure your browser to use the above SOCKS proxy with `port=8082` and `host=localhost` 16 | 3. Now, you can access IPs assigned by kubernetes directly from your browser 17 | 18 | ### Start Learning 19 | 1. Starting Learning Kuberneted from here: https://meteorhacks.com/learn-kubernetes-the-future-of-the-cloud.html 20 | 2. Then you can choose any tutorial you like and start playing with kubernetes 21 | -------------------------------------------------------------------------------- /kube-init.sh: -------------------------------------------------------------------------------- 1 | UBUNTU_DISTRO=`uname -a | grep Ubuntu` 2 | ARCHI=`uname -m` 3 | 4 | if [ ! "$UBUNTU_DISTRO" ]; then 5 | echo "=> kube-init requires a Ubuntu distro (64 bit)" 6 | exit 1 7 | fi 8 | 9 | if [ $ARCHI != "x86_64" ]; then 10 | echo "=> kube-init requires a 64 bit Ubuntu distro" 11 | exit 1 12 | fi 13 | 14 | # Install Docker 15 | wget -qO- https://get.docker.com/ | sh 16 | 17 | ## ETCD 18 | docker run \ 19 | -d \ 20 | --net=host \ 21 | quay.io/coreos/etcd:v2.0.9 \ 22 | --addr=127.0.0.1:4001 \ 23 | --bind-addr=0.0.0.0:4001 \ 24 | --data-dir=/var/etcd/data 25 | 26 | ## HyperKube apiserver 27 | # here we set the address to `0.0.0.0` 28 | # that's because we need to bind the api server with all IPs. 29 | # So, in kube-dns `kube2sky` can connect to api server via 30 | # docker's IP bridge IP 31 | # otherwise, we need to go through a lot of security related stuff 32 | docker run \ 33 | --net=host \ 34 | -d \ 35 | -v /var/run/docker.sock:/var/run/docker.sock\ 36 | meteorhacks/hyperkube \ 37 | /hyperkube apiserver \ 38 | --portal_net=10.0.0.1/24 \ 39 | --address=0.0.0.0 \ 40 | --etcd_servers=http://127.0.0.1:4001 \ 41 | --cluster_name=kubernetes \ 42 | --v=2 43 | 44 | ## HyperKube controller-manager 45 | docker run \ 46 | --net=host \ 47 | -d \ 48 | -v /var/run/docker.sock:/var/run/docker.sock\ 49 | meteorhacks/hyperkube \ 50 | /hyperkube controller-manager \ 51 | --master=127.0.0.1:8080 \ 52 | --machines=127.0.0.1 \ 53 | --sync_nodes=true \ 54 | --v=2 55 | 56 | ## HyperKube scheduler 57 | docker run \ 58 | --net=host \ 59 | -d \ 60 | -v /var/run/docker.sock:/var/run/docker.sock\ 61 | meteorhacks/hyperkube \ 62 | /hyperkube scheduler \ 63 | --master=127.0.0.1:8080 \ 64 | --v=2 65 | 66 | ## HyperKube kubelet 67 | docker run \ 68 | --net=host \ 69 | -d \ 70 | -v /var/run/docker.sock:/var/run/docker.sock\ 71 | meteorhacks/hyperkube \ 72 | /hyperkube kubelet \ 73 | --api_servers=http://127.0.0.1:8080 \ 74 | --v=2 \ 75 | --address=0.0.0.0 \ 76 | --hostname_override=127.0.0.1 \ 77 | --cluster_dns=10.0.0.10 \ 78 | --cluster_domain="kubernetes.local" \ 79 | --config=/etc/kubernetes/manifests 80 | 81 | ## Proxy which changes IP Tables Rules 82 | docker run \ 83 | -d \ 84 | --net=host \ 85 | --privileged \ 86 | meteorhacks/hyperkube \ 87 | /hyperkube proxy \ 88 | --master=http://127.0.0.1:8080 \ 89 | --v=2 90 | 91 | ## kubectl 92 | docker run --rm -v /usr/local/bin:/_bin meteorhacks/hyperkube /bin/bash -c "cp /kubectl /_bin" 93 | chmod +x /usr/local/bin/kubectl 94 | 95 | ## Add DNS Support 96 | cat < /tmp/kube-dns-rc.yaml 97 | apiVersion: v1beta3 98 | kind: ReplicationController 99 | metadata: 100 | labels: 101 | k8s-app: kube-dns 102 | name: kube-dns 103 | namespace: default 104 | spec: 105 | replicas: 1 106 | selector: 107 | k8s-app: kube-dns 108 | template: 109 | metadata: 110 | labels: 111 | k8s-app: kube-dns 112 | spec: 113 | dnsPolicy: "Default" 114 | containers: 115 | - args: [ 116 | "-listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001", 117 | "-initial-cluster-token=skydns-etcd", 118 | "-advertise-client-urls=http://127.0.0.1:4001" 119 | ] 120 | image: quay.io/coreos/etcd:v2.0.3 121 | name: etcd 122 | - args: [ 123 | "-domain=kubernetes.local.", 124 | # we are using docker's default bridge IP here 125 | # that's the only way we can connect inside from the pod 126 | "--kube_master_url=http://172.17.42.1:8080" 127 | ] 128 | image: gcr.io/google_containers/kube2sky:1.9 129 | name: kube2sky 130 | - args: [ 131 | "-machines=http://localhost:4001", 132 | "-addr=0.0.0.0:53", 133 | "-domain=kubernetes.local.", 134 | ] 135 | image: gcr.io/google_containers/skydns:2015-03-11-001 136 | name: skydns 137 | ports: 138 | - containerPort: 53 139 | name: dns 140 | protocol: UDP 141 | EOF 142 | 143 | cat < /tmp/kube-dns-service.yaml 144 | apiVersion: v1beta3 145 | kind: Service 146 | metadata: 147 | labels: 148 | k8s-app: kube-dns 149 | name: kube-dns 150 | namespace: default 151 | spec: 152 | portalIP: 10.0.0.10 153 | ports: 154 | - port: 53 155 | protocol: UDP 156 | targetPort: 53 157 | selector: 158 | k8s-app: kube-dns 159 | EOF 160 | 161 | waitFor() { 162 | cmd=$1 163 | while [ 1 ]; do 164 | ok=$(eval $cmd) 165 | if [ "$ok" ]; then 166 | break 167 | fi 168 | sleep 1 169 | done 170 | } 171 | 172 | echo 173 | echo "=> Waiting for ETCD. (takes upto 2-5 minute)" 174 | waitFor "wget -qO- http://127.0.0.1:4001/version | grep etcd" 175 | echo "=> ETCD is now online." 176 | 177 | echo 178 | echo "=> Waiting for Kubernates API. (takes upto 2-5 minute)" 179 | waitFor "wget -qO- http://127.0.0.1:8080/version | grep major" 180 | echo "=> Kubernates API is now online." 181 | 182 | echo 183 | echo "=> Setting up DNS confgurations" 184 | 185 | kubectl create -f /tmp/kube-dns-rc.yaml 186 | kubectl create -f /tmp/kube-dns-service.yaml 187 | 188 | rm /tmp/kube-dns-rc.yaml /tmp/kube-dns-service.yaml 189 | 190 | echo 191 | echo "=> Waiting for DNS confgurations (takes upto 2-5 minute)" 192 | waitFor 'kubectl get pod -l k8s-app=kube-dns | grep Running | grep "3/3"' 193 | echo "=> DNS confguration completed." 194 | 195 | ## Done 196 | echo 197 | echo "------------------------------------------------------------------" 198 | echo "=> Installed a Standalone Kubernates Cluster!" 199 | echo "-> type "kubectl" to start playing with the cluster" 200 | echo "-> to learn about Kubernetes, visit here: http://goo.gl/jmxn2W" 201 | echo "------------------------------------------------------------------" 202 | echo 203 | --------------------------------------------------------------------------------