github.com/enmand/kubernetes@v1.2.0-alpha.0/docs/getting-started-guides/fedora/fedora_ansible_config.md (about) 1 <!-- BEGIN MUNGE: UNVERSIONED_WARNING --> 2 3 <!-- BEGIN STRIP_FOR_RELEASE --> 4 5 <img src="http://kubernetes.io/img/warning.png" alt="WARNING" 6 width="25" height="25"> 7 <img src="http://kubernetes.io/img/warning.png" alt="WARNING" 8 width="25" height="25"> 9 <img src="http://kubernetes.io/img/warning.png" alt="WARNING" 10 width="25" height="25"> 11 <img src="http://kubernetes.io/img/warning.png" alt="WARNING" 12 width="25" height="25"> 13 <img src="http://kubernetes.io/img/warning.png" alt="WARNING" 14 width="25" height="25"> 15 16 <h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2> 17 18 If you are using a released version of Kubernetes, you should 19 refer to the docs that go with that version. 20 21 <strong> 22 The latest 1.0.x release of this document can be found 23 [here](http://releases.k8s.io/release-1.0/docs/getting-started-guides/fedora/fedora_ansible_config.md). 24 25 Documentation for other releases can be found at 26 [releases.k8s.io](http://releases.k8s.io). 27 </strong> 28 -- 29 30 <!-- END STRIP_FOR_RELEASE --> 31 32 <!-- END MUNGE: UNVERSIONED_WARNING --> 33 Configuring Kubernetes on [Fedora](http://fedoraproject.org) via [Ansible](http://www.ansible.com/home) 34 ------------------------------------------------------------------------------------------------------- 35 36 Configuring Kubernetes on Fedora via Ansible offers a simple way to quickly create a clustered environment with little effort. 37 38 **Table of Contents** 39 40 - [Prerequisites](#prerequisites) 41 - [Architecture of the cluster](#architecture-of-the-cluster) 42 - [Setting up ansible access to your nodes](#setting-up-ansible-access-to-your-nodes) 43 - [Setting up the cluster](#setting-up-the-cluster) 44 - [Testing and using your new cluster](#testing-and-using-your-new-cluster) 45 46 ## Prerequisites 47 48 1. Host able to run ansible and able to clone the following repo: [kubernetes](https://github.com/kubernetes/kubernetes.git) 49 2. A Fedora 21+ host to act as cluster master 50 3. As many Fedora 21+ hosts as you would like, that act as cluster nodes 51 52 The hosts can be virtual or bare metal. Ansible will take care of the rest of the configuration for you - configuring networking, installing packages, handling the firewall, etc. This example will use one master and two nodes. 53 54 ## Architecture of the cluster 55 56 A Kubernetes cluster requires etcd, a master, and n nodes, so we will create a cluster with three hosts, for example: 57 58 ```console 59 master,etcd = kube-master.example.com 60 node1 = kube-node-01.example.com 61 node2 = kube-node-02.example.com 62 ``` 63 64 **Make sure your local machine has** 65 66 - ansible (must be 1.9.0+) 67 - git 68 - python-netaddr 69 70 If not 71 72 ```sh 73 yum install -y ansible git python-netaddr 74 ``` 75 76 **Now clone down the Kubernetes repository** 77 78 ```sh 79 git clone https://github.com/kubernetes/contrib.git 80 cd contrib/ansible 81 ``` 82 83 **Tell ansible about each machine and its role in your cluster** 84 85 Get the IP addresses from the master and nodes. Add those to the `~/contrib/ansible/inventory` file on the host running Ansible. 86 87 ```console 88 [masters] 89 kube-master.example.com 90 91 [etcd] 92 kube-master.example.com 93 94 [nodes] 95 kube-node-01.example.com 96 kube-node-02.example.com 97 ``` 98 99 ## Setting up ansible access to your nodes 100 101 If you already are running on a machine which has passwordless ssh access to the kube-master and kube-node-{01,02} nodes, and 'sudo' privileges, simply set the value of `ansible_ssh_user` in `~/contrib/ansible/group_vars/all.yaml` to the username which you use to ssh to the nodes (i.e. `fedora`), and proceed to the next step... 102 103 *Otherwise* setup ssh on the machines like so (you will need to know the root password to all machines in the cluster). 104 105 edit: ~/contrib/ansible/group_vars/all.yml 106 107 ```yaml 108 ansible_ssh_user: root 109 ``` 110 111 **Configuring ssh access to the cluster** 112 113 If you already have ssh access to every machine using ssh public keys you may skip to [setting up the cluster](#setting-up-the-cluster) 114 115 Make sure your local machine (root) has an ssh key pair if not 116 117 ```sh 118 ssh-keygen 119 ``` 120 121 Copy the ssh public key to **all** nodes in the cluster 122 123 ```sh 124 for node in kube-master.example.com kube-node-01.example.com kube-node-02.example.com; do 125 ssh-copy-id ${node} 126 done 127 ``` 128 129 ## Setting up the cluster 130 131 Although the default value of variables in `~/contrib/ansible/group_vars/all.yml` should be good enough, if not, change them as needed. 132 133 edit: ~/contrib/ansible/group_vars/all.yml 134 135 **Configure access to kubernetes packages** 136 137 Modify `source_type` as below to access kubernetes packages through the package manager. 138 139 ```yaml 140 source_type: packageManager 141 ``` 142 143 **Configure the IP addresses used for services** 144 145 Each Kubernetes service gets its own IP address. These are not real IPs. You need only select a range of IPs which are not in use elsewhere in your environment. 146 147 ```yaml 148 kube_service_addresses: 10.254.0.0/16 149 ``` 150 151 **Managing flannel** 152 153 Modify `flannel_subnet`, `flannel_prefix` and `flannel_host_prefix` only if defaults are not appropriate for your cluster. 154 155 156 **Managing add on services in your cluster** 157 158 Set `cluster_logging` to false or true (default) to disable or enable logging with elasticsearch. 159 160 ```yaml 161 cluster_logging: true 162 ``` 163 164 Turn `cluster_monitoring` to true (default) or false to enable or disable cluster monitoring with heapster and influxdb. 165 166 ```yaml 167 cluster_monitoring: true 168 ``` 169 170 Turn `dns_setup` to true (recommended) or false to enable or disable whole DNS configuration. 171 172 ```yaml 173 dns_setup: true 174 ``` 175 176 **Tell ansible to get to work!** 177 178 This will finally setup your whole Kubernetes cluster for you. 179 180 ```sh 181 cd ~/contrib/ansible/ 182 183 ./setup.sh 184 ``` 185 186 ## Testing and using your new cluster 187 188 That's all there is to it. It's really that easy. At this point you should have a functioning Kubernetes cluster. 189 190 **Show kubernetes nodes** 191 192 Run the following on the kube-master: 193 194 ```sh 195 kubectl get nodes 196 ``` 197 198 **Show services running on masters and nodes** 199 200 ```sh 201 systemctl | grep -i kube 202 ``` 203 204 **Show firewall rules on the masters and nodes** 205 206 ```sh 207 iptables -nvL 208 ``` 209 210 **Create /tmp/apache.json on the master with the following contents and deploy pod** 211 212 ```json 213 { 214 "kind": "Pod", 215 "apiVersion": "v1", 216 "metadata": { 217 "name": "fedoraapache", 218 "labels": { 219 "name": "fedoraapache" 220 } 221 }, 222 "spec": { 223 "containers": [ 224 { 225 "name": "fedoraapache", 226 "image": "fedora/apache", 227 "ports": [ 228 { 229 "hostPort": 80, 230 "containerPort": 80 231 } 232 ] 233 } 234 ] 235 } 236 } 237 ``` 238 239 ```sh 240 kubectl create -f /tmp/apache.json 241 ``` 242 243 **Check where the pod was created** 244 245 ```sh 246 kubectl get pods 247 ``` 248 249 **Check Docker status on nodes** 250 251 ```sh 252 docker ps 253 docker images 254 ``` 255 256 **After the pod is 'Running' Check web server access on the node** 257 258 ```sh 259 curl http://localhost 260 ``` 261 262 That's it ! 263 264 265 <!-- BEGIN MUNGE: GENERATED_ANALYTICS --> 266 []() 267 <!-- END MUNGE: GENERATED_ANALYTICS -->