├── images ├── kube.png └── rancher.png ├── .gitignore └── README.md /images/kube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polinchw/rancher-kubernetes-on-bare-metal/HEAD/images/kube.png -------------------------------------------------------------------------------- /images/rancher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/polinchw/rancher-kubernetes-on-bare-metal/HEAD/images/rancher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### JetBrains template 3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 5 | 6 | # User-specific stuff 7 | .idea/**/workspace.xml 8 | .idea/**/tasks.xml 9 | .idea/**/usage.statistics.xml 10 | .idea/**/dictionaries 11 | .idea/**/shelf 12 | 13 | # Sensitive or high-churn files 14 | .idea/**/dataSources/ 15 | .idea/**/dataSources.ids 16 | .idea/**/dataSources.local.xml 17 | .idea/**/sqlDataSources.xml 18 | .idea/**/dynamic.xml 19 | .idea/**/uiDesigner.xml 20 | .idea/**/dbnavigator.xml 21 | 22 | # Gradle 23 | .idea/**/gradle.xml 24 | .idea/**/libraries 25 | 26 | # Gradle and Maven with auto-import 27 | # When using Gradle or Maven with auto-import, you should exclude module files, 28 | # since they will be recreated, and may cause churn. Uncomment if using 29 | # auto-import. 30 | # .idea/modules.xml 31 | # .idea/*.iml 32 | # .idea/modules 33 | 34 | # CMake 35 | cmake-build-*/ 36 | 37 | # Mongo Explorer plugin 38 | .idea/**/mongoSettings.xml 39 | 40 | # File-based project format 41 | *.iws 42 | 43 | # IntelliJ 44 | out/ 45 | 46 | # mpeltonen/sbt-idea plugin 47 | .idea_modules/ 48 | 49 | # JIRA plugin 50 | atlassian-ide-plugin.xml 51 | 52 | # Cursive Clojure plugin 53 | .idea/replstate.xml 54 | 55 | # Crashlytics plugin (for Android Studio and IntelliJ) 56 | com_crashlytics_export_strings.xml 57 | crashlytics.properties 58 | crashlytics-build.properties 59 | fabric.properties 60 | 61 | # Editor-based Rest Client 62 | .idea/httpRequests 63 | 64 | /.idea/ 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deploying Kubernetes on bare metal with Rancher 2.0 2 | 3 | ## Contents 4 | 5 | + Install Rancher server 6 | + Create a Kubernetes cluster 7 | + Add Kubernetes nodes 8 | + Install StorageOS as the Kubernetes storage class 9 | + Understand Nginx Ingress in Rancher 10 | 11 | 12 | ### Install Rancher 13 | 14 | Create a VM with Docker and Docker Compose installed and install Rancher 2.0 with docker compose: 15 | 16 | + Rancher docker-compose file: 17 | [docker-compose.yaml](https://github.com/polinchw/rancher-docker-compose/blob/master/docker-compose.yaml) 18 | 19 | + Run these commands to install Rancher with docker compose: 20 | + ```git clone https://github.com/polinchw/rancher-docker-compose ``` 21 | + ```cd rancher-docker-compose ``` 22 | + ```docker-compose up -d``` 23 | 24 | ### Create your Kubernetes cluster with Rancher 25 | 26 | Install a custom Kubernetes cluster with Rancher. Use the 'Custom' cluster. 27 | 28 | ![Cluster!](images/rancher.png) 29 | 30 | ### Add Kubernetes nodes and join the Kubernetes cluster 31 | 32 | Run the following commands on all the VMs that your Kubernetes cluster will run on. The final docker command 33 | will have the VM join the new Kubernetes cluster. 34 | 35 | Replace the **--server** and **--token** with your Rancher server and cluster token. 36 | 37 | ``` 38 | #!/bin/bash 39 | 40 | #sudo apt update 41 | #sudo apt -y dist-upgrade 42 | 43 | #Ubuntu (Docker install) 44 | #sudo apt -y install docker.io 45 | 46 | sudo apt -y install linux-image-extra-$(uname -r) 47 | 48 | #Debian 9 (Docker install) 49 | #sudo apt -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common 50 | #curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - 51 | #sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" 52 | #sudo apt update 53 | #sudo apt -y install docker-ce 54 | 55 | sudo mkdir -p /etc/systemd/system/docker.service.d/ 56 | sudo cat < /etc/systemd/system/docker.service.d/mount_propagation_flags.conf 57 | [Service] 58 | MountFlags=shared 59 | EOF 60 | 61 | sudo systemctl daemon-reload 62 | sudo systemctl restart docker.service 63 | 64 | #This is dependent on your Rancher server 65 | sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.1.0-rc9 --server https://75.77.159.159 --token rb8k8kkqw55jqnqbbf4ssdjqtw6hndhfxxcghgv8257kx4p6qsqq55 --ca-checksum 641b2888ce3f1091d20149a495d10457154428f440475b42291b6af1b6c0dd06 --etcd --controlplane --worker 66 | ``` 67 | 68 | ### Download the kub config file for the cluster 69 | 70 | ![Helloservice!](images/kube.png) 71 | 72 | After you download the kub config file you can use it by running this command: 73 | 74 | ``` 75 | export KUBECONFIG=$HOME/.kube/rancher-config 76 | ``` 77 | 78 | ### Install Helm on the cluster 79 | 80 | ``` 81 | git clone https://github.com/polinchw/set-up-tiller 82 | 83 | cd set-up-tiller 84 | 85 | chmod u+x set-up-tiller.sh 86 | 87 | ./set-up-tiller.sh 88 | 89 | helm init --service-account tiller 90 | 91 | ``` 92 | 93 | ### Install StorageOS Helm Chart 94 | 95 | ``` 96 | helm repo add storageos https://charts.storageos.com 97 | helm install --name storageos --namespace storageos-operator --version 1.1.3 storageos/storageoscluster-operator 98 | ``` 99 | 100 | ## Add the Storage OS Secret 101 | ``` 102 | apiVersion: v1 103 | kind: Secret 104 | metadata: 105 | name: storageos-api 106 | namespace: default 107 | labels: 108 | app: storageos 109 | type: kubernetes.io/storageos 110 | data: 111 | # echo -n '' | base64 112 | apiUsername: c3RvcmFnZW9z 113 | apiPassword: c3RvcmFnZW9z 114 | 115 | ``` 116 | 117 | ## Add the StorageOSCluster 118 | ``` 119 | apiVersion: storageos.com/v1 120 | kind: StorageOSCluster 121 | metadata: 122 | name: example-storageos 123 | namespace: default 124 | spec: 125 | secretRefName: storageos-api 126 | secretRefNamespace: default 127 | csi: 128 | enable: true 129 | 130 | ``` 131 | 132 | 133 | ### Set StorageOS as the default storage class 134 | 135 | kubectl patch storageclass fast -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' 136 | 137 | ### Using the default Nginx Igress 138 | 139 | Rancher automatically installs the nginx ingress controller on all the nodes in the cluster. 140 | If you are able to expose one of the VMs in the cluster to the outside world with a public IP 141 | then you can connect to the ingress based services on ports 80 and 443. 142 | 143 | Any app you want to be accessible through the default nginx ingress must be added to the 'default' 144 | project in Rancher. 145 | 146 | --------------------------------------------------------------------------------