Skip to content
README.md 7.83 KiB
Newer Older
Smaine Kahlouch's avatar
Smaine Kahlouch committed
kubernetes-ansible
========

Install and configure a kubernetes cluster including network plugin and optionnal addons.
Smaine Kahlouch's avatar
Smaine Kahlouch committed
Based on [CiscoCloud](https://github.com/CiscoCloud/kubernetes-ansible) work.

Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Requirements
Smaine Kahlouch's avatar
Smaine Kahlouch committed
Tested on **Debian Jessie** and **Ubuntu** (14.10, 15.04, 15.10).
The target servers must have access to the Internet in order to pull docker imaqes.
Smaine Kahlouch's avatar
Smaine Kahlouch committed
The firewalls are not managed, you'll need to implement your own rules the way you used to.
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
Ansible v1.9.x

### Components
Smaine Kahlouch's avatar
Smaine Kahlouch committed
* [kubernetes](https://github.com/kubernetes/kubernetes/releases) v1.0.6
* [etcd](https://github.com/coreos/etcd/releases) v2.2.0
* [calicoctl](https://github.com/projectcalico/calico-docker/releases) v0.5.1
* [flanneld](https://github.com/coreos/flannel/releases) v0.5.3
* [docker](https://www.docker.com/) v1.8.3
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed

Ansible
-------------------------
Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Download binaries
A role allows to download required binaries which will be stored in a directory defined by the variable
Smaine Kahlouch's avatar
Smaine Kahlouch committed
**'local_release_dir'** (by default /tmp).
Please ensure that you have enough disk space there (about **1G**).
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
**Note**: Whenever you'll need to change the version of a software, you'll have to erase the content of this directory.
Smaine Kahlouch's avatar
Smaine Kahlouch committed


### Variables
Smaine Kahlouch's avatar
Smaine Kahlouch committed
The main variables to change are located in the directory ```environments/[env_name]/group_vars/k8s-cluster.yml```.
Smaine Kahlouch's avatar
Smaine Kahlouch committed

### Inventory
Below is an example of an inventory.
Note : The bgp vars local_as and peers are not mandatory if the var "peer_with_router" is set to false
By default this variable is set to false and therefore all the nodes are configure in "node-mesh" mode.
In node-mesh mode the nodes peers with all the nodes in order to exchange routes.

```
[downloader]
10.99.0.26

[kube-master]
# NB : the br_addr must be in the {{ calico_pool }} subnet
# it will assign a /24 subnet per node
10.99.0.26 br_addr=10.99.64.1

[etcd]
10.99.0.26

[kube-node]
10.99.0.4
10.99.0.5
10.99.0.6
10.99.0.36
10.99.0.37

[itx2]
10.99.0.26 br_addr=10.99.16.1
10.99.0.4 br_addr=10.99.65.1 local_as=xxxxxxxx
10.99.0.5 br_addr=10.99.66.1 local_as=xxxxxxxx
10.99.0.6 br_addr=10.99.69.1 local_as=xxxxxxxx

[rmv]
10.99.0.36 br_addr=10.99.67.1 local_as=xxxxxxxx
10.99.0.37 br_addr=10.99.68.1 local_as=xxxxxxxx

[k8s-cluster:children]
kube-node
kube-master

[itx2:vars]
peers=[{"router_id": "10.99.0.2", "as": "65xxx"}, {"router_id": "10.99.0.3", "as": "65xxx"}]

[rmv:vars]
peers=[{"router_id": "10.99.0.34", "as": "65xxx"}, {"router_id": "10.99.0.35", "as": "65xxx"}]
```

Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Playbook
```
---
- hosts: downloader
  sudo: no
  roles:
    - { role: download, tags: download }

- hosts: k8s-cluster
  roles:
    - { role: etcd, tags: etcd }
    - { role: docker, tags: docker }
    - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }
Smaine Kahlouch's avatar
Smaine Kahlouch committed
    - { role: dnsmasq, tags: dnsmasq }
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
- hosts: kube-master
  roles:
    - { role: kubernetes/master, tags: master }

- hosts: kube-node
  roles:
    - { role: kubernetes/node, tags: node }

- hosts: kube-master
  roles:
    - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps']  }
    - { role: apps/k8s-fabric8, tags: ['fabric8', 'apps']  }
Smaine Kahlouch's avatar
Smaine Kahlouch committed
```

### Run
Smaine Kahlouch's avatar
Smaine Kahlouch committed
It is possible to define variables for different environments.
For instance, in order to deploy the cluster on 'dev' environment run the following command.
```
ansible-playbook -i environments/dev/inventory cluster.yml -u root
Smaine Kahlouch's avatar
Smaine Kahlouch committed
```

Kubernetes
-------------------------
Smaine Kahlouch's avatar
Smaine Kahlouch committed

### Network Overlay
You can choose between 2 network plugins. Only one must be chosen.
Smaine Kahlouch's avatar
Smaine Kahlouch committed

* **flannel**: gre/vxlan (layer 2) networking. ([official docs]('https://github.com/coreos/flannel'))

* **calico**: bgp (layer 3) networking. ([official docs]('http://docs.projectcalico.org/en/0.13/'))
Smaine Kahlouch's avatar
Smaine Kahlouch committed

The choice is defined with the variable '**kube_network_plugin**'
Smaine Kahlouch's avatar
Smaine Kahlouch committed

### Expose a service
Smaine Kahlouch's avatar
Smaine Kahlouch committed
There are several loadbalancing solutions.
The ones i found suitable for kubernetes are [Vulcand]('http://vulcand.io/') and [Haproxy]('http://www.haproxy.org/')
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
My cluster is working with haproxy and kubernetes services are configured with the loadbalancing type '**nodePort**'.
Smaine Kahlouch's avatar
Smaine Kahlouch committed
eg: each node opens the same tcp port and forwards the traffic to the target pod wherever it is located.

Then Haproxy can be configured to request kubernetes's api in order to loadbalance on the proper tcp port on the nodes.
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
Please refer to the proper kubernetes documentation on [Services]('https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/services.md')
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Check cluster status

#### Kubernetes components
Smaine Kahlouch's avatar
Smaine Kahlouch committed
Master processes : kube-apiserver, kube-scheduler, kube-controller, kube-proxy
Nodes processes : kubelet, kube-proxy, [calico-node|flanneld]

* Check the status of the processes
```
systemctl status [process_name]
```

* Check the logs
```
journalctl -ae -u [process_name]
```

* Check the NAT rules
```
iptables -nLv -t nat
```

Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Available apps, installation procedure

There are two ways of installing new apps

#### Ansible galaxy

Smaine Kahlouch's avatar
Smaine Kahlouch committed
Additionnal apps can be installed with ```ansible-galaxy```.
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
you'll need to edit the file '*requirements.yml*' in order to chose needed apps.
The list of available apps are available [there](https://github.com/ansibl8s)
Smaine Kahlouch's avatar
Smaine Kahlouch committed

For instance if you will probably want to install a [dns server](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) as it is **strongly recommanded**.
Smaine Kahlouch's avatar
Smaine Kahlouch committed
In order to use this role you'll need the following entries in the file '*requirements.yml*' 
Smaine Kahlouch's avatar
Smaine Kahlouch committed
- src: https://github.com/ansibl8s/k8s-common.git
  path: roles/apps
  # version: v1.0

- src: https://github.com/ansibl8s/k8s-kubedns.git
Smaine Kahlouch's avatar
Smaine Kahlouch committed
  path: roles/apps
  # version: v1.0
Smaine Kahlouch's avatar
Smaine Kahlouch committed
**Note**: the role common is required by all the apps and provides the tasks and libraries needed.

Smaine Kahlouch's avatar
Smaine Kahlouch committed
And empty the apps directory
```
rm -rf roles/apps/*
```

Then download the roles with ansible-galaxy
```
ansible-galaxy install -r requirements.yml
```

Smaine Kahlouch's avatar
Smaine Kahlouch committed
#### Git submodules
Alternatively the roles can be installed as git submodules.
That way is easier if you want to do some changes and commit them.

You can list available submodules with the following command:
```
grep path .gitmodules | sed 's/.*= //'
```

For instance if you will probably want to install a [dns server](https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns) as it is **strongly recommanded**.
Please refer to the [k8s-kubdns readme](https://github.com/ansibl8s/k8s-kubedns) for additionnal info.

Smaine Kahlouch's avatar
Smaine Kahlouch committed
In order to use this role you'll need to follow these steps
```
git submodule init roles/apps/k8s-common roles/apps/k8s-kubedns
git submodule update
```

Finally update the playbook ```apps.yml``` with the chosen roles, and run it
```
...
- hosts: kube-master
  roles:
    - { role: apps/k8s-kubedns, tags: ['kubedns', 'apps']  }

```
ansible-playbook -i environments/dev/inventory apps.yml -u root
```

Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
#### Calico networking
Check if the calico-node container is running
```
docker ps | grep calico
```

The **calicoctl** command allows to check the status of the network workloads.
* Check the status of Calico nodes
```
calicoctl status
```

* Show the configured network subnet for containers
```
calicoctl pool show
```

Smaine Kahlouch's avatar
Smaine Kahlouch committed
* Show the workloads (ip addresses of containers and their located)
Smaine Kahlouch's avatar
Smaine Kahlouch committed
```
calicoctl endpoint show --detail
```
#### Flannel networking

Smaine Kahlouch's avatar
Smaine Kahlouch committed
Congrats ! now you can walk through [kubernetes basics](http://kubernetes.io/v1.0/basicstutorials.html)
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
Known issues
-------------
Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Node reboot and Calico
Smaine Kahlouch's avatar
Smaine Kahlouch committed
There is a major issue with calico-kubernetes version 0.5.1 and kubernetes prior to 1.1 :
Smaine Kahlouch's avatar
Smaine Kahlouch committed
After host reboot, the pods networking are not configured again, they are started without any network configuration.
Smaine Kahlouch's avatar
Smaine Kahlouch committed
This issue will be fixed when kubernetes 1.1 will be released as described in this [issue](https://github.com/projectcalico/calico-kubernetes/issues/34)
Smaine Kahlouch's avatar
Smaine Kahlouch committed

Smaine Kahlouch's avatar
Smaine Kahlouch committed
### Monitoring addon
Smaine Kahlouch's avatar
Smaine Kahlouch committed
Until now i didn't managed to get the monitoring addon working.
Smaine Kahlouch's avatar
Smaine Kahlouch committed

### Apiserver listen on secure port only
Smaine Kahlouch's avatar
Smaine Kahlouch committed
Currently the api-server listens on both secure and insecure ports.
The insecure port is mainly used for calico.
Will be fixed soon.