Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ahmadronaghdev/aef2feb1ad02c63c23517c2966d6a22f to your computer and use it in GitHub Desktop.
Save ahmadronaghdev/aef2feb1ad02c63c23517c2966d6a22f to your computer and use it in GitHub Desktop.

Revisions

  1. @ruanbekker ruanbekker revised this gist Dec 3, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -194,4 +194,5 @@ kubectl get pods --namespace=sock-shop
    - https://github.com/kubernetes/kubernetes/tree/master/examples
    - http://blog.pichuang.com.tw/Installing-Kubernetes-on-Linux-with-kubeadm/
    - https://blog.alexellis.io/kubernetes-in-10-minutes/
    - http://alexander.holbreich.org/kubernetes-on-ubuntu/
    - http://alexander.holbreich.org/kubernetes-on-ubuntu/
    - http://alesnosek.com/blog/2017/02/14/accessing-kubernetes-pods-from-outside-of-the-cluster/
  2. @ruanbekker ruanbekker revised this gist Dec 3, 2017. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -180,6 +180,16 @@ kubectl proxy --address 0.0.0.0 --port 8001 --accept-hosts='^*$'
    ssh -L 8001:127.0.0.1:8001 -N
    ```

    ## Deploy a [Web Application](https://www.mirantis.com/blog/how-install-kubernetes-kubeadm/):

    ```
    kubectl create namespace sock-shop
    kubectl apply -n sock-shop -f "https://github.com/microservices-demo/microservices-demo/blob/master/deploy/kubernetes/complete-demo.yaml?raw=true"
    kubectl -n sock-shop get svc front-end
    kubectl get pods --namespace=sock-shop
    ```
    ```
    ## Resources:
    - https://github.com/kubernetes/kubernetes/tree/master/examples
    - http://blog.pichuang.com.tw/Installing-Kubernetes-on-Linux-with-kubeadm/
  3. @ruanbekker ruanbekker revised this gist Dec 3, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -181,7 +181,7 @@ ssh -L 8001:127.0.0.1:8001 -N
    ```

    ## Resources:

    - https://github.com/kubernetes/kubernetes/tree/master/examples
    - http://blog.pichuang.com.tw/Installing-Kubernetes-on-Linux-with-kubeadm/
    - https://blog.alexellis.io/kubernetes-in-10-minutes/
    - http://alexander.holbreich.org/kubernetes-on-ubuntu/
  4. @ruanbekker ruanbekker revised this gist Dec 3, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -174,7 +174,10 @@ kubectl exec -it guids-6d7b75568d-sndbd sh
    ```
    kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
    kubectl describe services kubernetes-dashboard --namespace=kube-system
    kubectl proxy --address 0.0.0.0 --port 9090 --accept-hosts='^*$'
    kubectl proxy --address 0.0.0.0 --port 8001 --accept-hosts='^*$'
    # or if using localhost:
    ssh -L 8001:127.0.0.1:8001 -N
    ```

    ## Resources:
  5. @ruanbekker ruanbekker revised this gist Dec 2, 2017. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -169,6 +169,14 @@ kubectl logs guids-6d7b75568d-sndbd
    kubectl exec -it guids-6d7b75568d-sndbd sh
    ```

    ## Create the Dashboard Service:

    ```
    kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
    kubectl describe services kubernetes-dashboard --namespace=kube-system
    kubectl proxy --address 0.0.0.0 --port 9090 --accept-hosts='^*$'
    ```

    ## Resources:

    - http://blog.pichuang.com.tw/Installing-Kubernetes-on-Linux-with-kubeadm/
  6. @ruanbekker ruanbekker revised this gist Dec 2, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -144,6 +144,12 @@ kubectl describe pod guids-6d7b75568d-sndbd | grep IP
    IP: 192.168.144.66
    ```

    ## Master: Describing Services:

    ```
    kubectl describe services kubernetes-dashboard --namespace=kube-system
    ```

    ## Master: Testing the Service:

    ```
  7. @ruanbekker ruanbekker revised this gist Dec 2, 2017. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -151,6 +151,18 @@ curl 192.168.144.66:9000/guid
    {"guid":"dde5c4f1-d412-4acf-9ab3-bd81b347bc4f","container":"guids-6d7b75568d-sndbd"}
    ```

    ## Master: Getting the Logs:

    ```
    kubectl logs guids-6d7b75568d-sndbd
    ```

    ## Master: Exec into a Cointainer:

    ```
    kubectl exec -it guids-6d7b75568d-sndbd sh
    ```

    ## Resources:

    - http://blog.pichuang.com.tw/Installing-Kubernetes-on-Linux-with-kubeadm/
  8. @ruanbekker ruanbekker created this gist Dec 2, 2017.
    158 changes: 158 additions & 0 deletions setup-kubernetes-ubuntu-16.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,158 @@
    ## Master: Dependencies

    ```
    apt update && apt upgrade -y
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
    deb http://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    apt-get update
    apt install linux-image-extra-virtual ca-certificates curl software-properties-common -y
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
    apt update
    ```

    ## Master: Install Docker, Kubernetnes:

    ```
    apt install docker-ce kubelet kubeadm kubectl kubernetes-cni -y
    ```

    ## Master: Initialize the Kubernetes Cluster:

    ```
    kubeadm init --pod-network-cidr 192.168.0.0/16 --service-cidr 10.96.0.0/12 --service-dns-domain "k8s" --apiserver-advertise-address $(ifconfig eth0 | grep 'inet addr'| cut -d':' -f2 | awk '{print $1}')
    ```

    You should get information back on initiating commands as a normal user, as well as the network that you need to deploy as well as how to join worker nodes to the cluster.

    ## Master: Setup the Kubernetes Config:

    As a normal user:

    ```
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    export KUBECONFIG=$HOME/.kube/config
    export KUBECONFIG=$HOME/.kube/config | tee -a ~/.bashrc
    ```

    ## Master: Deploy a POD Network to the Cluster:

    As a normal user, deploy a [pod network](https://www.projectcalico.org/):

    ```
    kubectl apply -f http://docs.projectcalico.org/v2.3/getting-started/kubernetes/installation/hosted/kubeadm/1.6/calico.yaml
    ```

    ## Worker: Setup Dependencies and Install Kubernetes:

    ```
    apt update && apt upgrade -y
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
    deb http://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    apt-get update
    apt install linux-image-extra-virtual ca-certificates curl software-properties-common -y
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
    apt update
    apt install docker-ce kubelet kubeadm kubectl kubernetes-cni -y
    ```

    ## Worker: Setup the Kubernetes Config:

    As a normal user:

    ```
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    export KUBECONFIG=$HOME/.kube/config
    export KUBECONFIG=$HOME/.kube/config | tee -a ~/.bashrc
    ```

    ## Worker: Join the Node to the Cluster:

    From the output of the `kubeadm init`, you received a join token, which we will be running from the node that we would like to join:

    ```
    kubeadm join --token 51e20a.40a4599dbe3ca2e0 172.31.39.193:6443 --discovery-token-ca-cert-hash sha256:[long-string]
    ```

    ## Master: Check if the nodes are reachable:

    ```
    kubectl get nodes
    NAME STATUS ROLES AGE VERSION
    ip-172-31-32-88 Ready <none> 16m v1.8.4
    ip-172-31-39-193 Ready master 23m v1.8.4
    ```

    ## Master: Verify if all the Kube-System Containers are running:

    ```
    kubectl get all --namespace=kube-system
    ```

    ## Master: List the Pods:

    List the containers thats currently running:

    ```
    kubectl get pods
    NAME READY STATUS RESTARTS AGE
    guids-6d7b75568d-sndbd 0/1 ContainerCreating 0 5s
    ```

    ## Master: Deploy a Pod:

    Lets deploy a service into our kubernetes cluster:

    ```
    kubectl run guids --image=alexellis2/guid-service:latest --port 9000
    deployment "guids" created
    kubectl get pods
    NAME READY STATUS RESTARTS AGE
    guids-6d7b75568d-sndbd 1/1 Running 0 15s
    ```

    ## Master: Describe the Pod:

    Describe the Pod and get the IP:

    ```
    kubectl describe pod guids-6d7b75568d-sndbd | grep IP
    IP: 192.168.144.66
    ```

    ## Master: Testing the Service:

    ```
    curl 192.168.144.66:9000/guid
    {"guid":"dde5c4f1-d412-4acf-9ab3-bd81b347bc4f","container":"guids-6d7b75568d-sndbd"}
    ```

    ## Resources:

    - http://blog.pichuang.com.tw/Installing-Kubernetes-on-Linux-with-kubeadm/
    - https://blog.alexellis.io/kubernetes-in-10-minutes/
    - http://alexander.holbreich.org/kubernetes-on-ubuntu/