2015-07-12 04:04:52 +00:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-16 17:02:26 +00:00
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< h2 > PLEASE NOTE: This document applies to the HEAD of the source tree< / h2 >
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
2015-12-14 18:37:38 +00:00
<!-- TAG RELEASE_LINK, added by the munger automatically -->
2015-07-16 17:02:26 +00:00
< strong >
2015-11-03 18:17:57 +00:00
The latest release of this document can be found
[here ](http://releases.k8s.io/release-1.1/docs/getting-started-guides/fedora/fedora_ansible_config.md ).
2015-07-16 17:02:26 +00:00
Documentation for other releases can be found at
[releases.k8s.io ](http://releases.k8s.io ).
< / strong >
--
2015-07-13 22:15:35 +00:00
2015-07-12 04:04:52 +00:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-07-20 20:45:36 +00:00
Configuring Kubernetes on [Fedora ](http://fedoraproject.org ) via [Ansible ](http://www.ansible.com/home )
2015-06-22 19:39:35 +00:00
-------------------------------------------------------------------------------------------------------
2014-09-12 22:53:32 +00:00
2015-07-20 20:45:36 +00:00
Configuring Kubernetes on Fedora via Ansible offers a simple way to quickly create a clustered environment with little effort.
2014-09-12 22:53:32 +00:00
2015-06-22 19:39:35 +00:00
**Table of Contents**
2015-06-22 18:56:19 +00:00
2015-06-23 15:20:31 +00:00
- [Prerequisites ](#prerequisites )
- [Architecture of the cluster ](#architecture-of-the-cluster )
2015-07-19 15:53:44 +00:00
- [Setting up ansible access to your nodes ](#setting-up-ansible-access-to-your-nodes )
2015-06-23 15:20:31 +00:00
- [Setting up the cluster ](#setting-up-the-cluster )
- [Testing and using your new cluster ](#testing-and-using-your-new-cluster )
2015-06-22 18:56:19 +00:00
2015-07-17 22:35:41 +00:00
## Prerequisites
2014-09-12 22:53:32 +00:00
2015-08-27 17:16:34 +00:00
1. Host able to run ansible and able to clone the following repo: [kubernetes ](https://github.com/kubernetes/kubernetes.git )
2015-07-19 15:53:44 +00:00
2. A Fedora 21+ host to act as cluster master
3. As many Fedora 21+ hosts as you would like, that act as cluster nodes
2014-09-12 22:53:32 +00:00
2015-07-19 15:53:44 +00:00
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.
2014-10-28 22:57:07 +00:00
2015-03-24 02:17:28 +00:00
## Architecture of the cluster
2015-07-07 17:37:40 +00:00
A Kubernetes cluster requires etcd, a master, and n nodes, so we will create a cluster with three hosts, for example:
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```console
2015-07-19 15:53:44 +00:00
master,etcd = kube-master.example.com
node1 = kube-node-01.example.com
node2 = kube-node-02.example.com
2014-09-12 22:53:32 +00:00
```
2015-07-19 15:53:44 +00:00
**Make sure your local machine has**
2014-09-12 22:53:32 +00:00
2015-07-19 15:53:44 +00:00
- ansible (must be 1.9.0+)
- git
- python-netaddr
2014-09-12 22:53:32 +00:00
2015-07-19 15:53:44 +00:00
If not
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```sh
2015-07-19 15:53:44 +00:00
yum install -y ansible git python-netaddr
2014-09-12 22:53:32 +00:00
```
2015-07-20 20:45:36 +00:00
**Now clone down the Kubernetes repository**
2015-07-19 15:53:44 +00:00
```sh
2015-08-27 17:16:34 +00:00
git clone https://github.com/kubernetes/contrib.git
cd contrib/ansible
2015-07-19 15:53:44 +00:00
```
2014-10-28 22:57:07 +00:00
2015-07-19 15:53:44 +00:00
**Tell ansible about each machine and its role in your cluster**
2015-03-24 02:17:28 +00:00
2015-08-27 17:16:34 +00:00
Get the IP addresses from the master and nodes. Add those to the `~/contrib/ansible/inventory` file on the host running Ansible.
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```console
2014-09-12 22:53:32 +00:00
[masters]
2015-07-19 15:53:44 +00:00
kube-master.example.com
2014-09-12 22:53:32 +00:00
[etcd]
2015-07-19 15:53:44 +00:00
kube-master.example.com
2014-09-12 22:53:32 +00:00
2015-07-19 15:53:44 +00:00
[nodes]
kube-node-01.example.com
kube-node-02.example.com
2014-09-12 22:53:32 +00:00
```
2015-07-19 15:53:44 +00:00
## Setting up ansible access to your nodes
2015-03-24 02:17:28 +00:00
2015-11-03 10:22:02 +00:00
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.yml` to the username which you use to ssh to the nodes (i.e. `fedora` ), and proceed to the next step...
2015-03-24 02:17:28 +00:00
*Otherwise* setup ssh on the machines like so (you will need to know the root password to all machines in the cluster).
2014-10-28 22:57:07 +00:00
2015-08-27 17:16:34 +00:00
edit: ~/contrib/ansible/group_vars/all.yml
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```yaml
2014-10-28 22:57:07 +00:00
ansible_ssh_user: root
2014-09-12 22:53:32 +00:00
```
2015-07-19 15:53:44 +00:00
**Configuring ssh access to the cluster**
2014-10-28 22:57:07 +00:00
2015-07-19 15:53:44 +00:00
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 )
2014-10-28 22:57:07 +00:00
2015-07-19 15:53:44 +00:00
Make sure your local machine (root) has an ssh key pair if not
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```sh
2015-07-19 15:53:44 +00:00
ssh-keygen
2014-09-12 22:53:32 +00:00
```
2015-07-19 15:53:44 +00:00
Copy the ssh public key to **all** nodes in the cluster
2015-03-24 02:17:28 +00:00
2015-07-19 02:01:59 +00:00
```sh
2015-07-19 15:53:44 +00:00
for node in kube-master.example.com kube-node-01.example.com kube-node-02.example.com; do
ssh-copy-id ${node}
done
2014-09-12 22:53:32 +00:00
```
2015-07-19 15:53:44 +00:00
## Setting up the cluster
2014-10-28 22:57:07 +00:00
2015-08-27 17:16:34 +00:00
Although the default value of variables in `~/contrib/ansible/group_vars/all.yml` should be good enough, if not, change them as needed.
2014-10-28 22:57:07 +00:00
2015-08-27 17:16:34 +00:00
edit: ~/contrib/ansible/group_vars/all.yml
2014-10-28 22:57:07 +00:00
2015-07-27 20:00:13 +00:00
**Configure access to kubernetes packages**
Modify `source_type` as below to access kubernetes packages through the package manager.
```yaml
source_type: packageManager
```
2015-07-19 15:53:44 +00:00
**Configure the IP addresses used for services**
2015-03-24 02:17:28 +00:00
2015-07-20 20:45:36 +00:00
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.
2014-10-28 22:57:07 +00:00
2015-07-19 15:53:44 +00:00
```yaml
kube_service_addresses: 10.254.0.0/16
2014-10-28 22:57:07 +00:00
```
2015-07-19 15:53:44 +00:00
**Managing flannel**
2014-10-28 22:57:07 +00:00
2015-07-19 15:53:44 +00:00
Modify `flannel_subnet` , `flannel_prefix` and `flannel_host_prefix` only if defaults are not appropriate for your cluster.
2015-03-26 03:02:20 +00:00
2015-07-19 15:53:44 +00:00
**Managing add on services in your cluster**
2015-03-26 03:02:20 +00:00
2015-07-19 15:53:44 +00:00
Set `cluster_logging` to false or true (default) to disable or enable logging with elasticsearch.
2015-07-17 02:01:02 +00:00
2015-07-19 15:53:44 +00:00
```yaml
cluster_logging: true
2015-03-26 03:02:20 +00:00
```
2015-07-19 15:53:44 +00:00
Turn `cluster_monitoring` to true (default) or false to enable or disable cluster monitoring with heapster and influxdb.
2015-03-24 02:17:28 +00:00
2015-07-19 15:53:44 +00:00
```yaml
cluster_monitoring: true
2014-10-28 22:57:07 +00:00
```
2015-07-19 15:53:44 +00:00
Turn `dns_setup` to true (recommended) or false to enable or disable whole DNS configuration.
2014-10-28 22:57:07 +00:00
2015-07-19 02:01:59 +00:00
```yaml
2015-07-19 15:53:44 +00:00
dns_setup: true
2014-10-28 22:57:07 +00:00
```
**Tell ansible to get to work!**
2014-09-12 22:53:32 +00:00
2015-07-20 20:45:36 +00:00
This will finally setup your whole Kubernetes cluster for you.
2015-03-24 02:17:28 +00:00
2015-07-19 02:01:59 +00:00
```sh
2015-08-27 17:16:34 +00:00
cd ~/contrib/ansible/
2015-07-19 15:53:44 +00:00
./setup.sh
2014-09-12 22:53:32 +00:00
```
2014-10-28 22:57:07 +00:00
## Testing and using your new cluster
2015-07-20 20:45:36 +00:00
That's all there is to it. It's really that easy. At this point you should have a functioning Kubernetes cluster.
2014-09-12 22:53:32 +00:00
2015-08-09 18:18:06 +00:00
**Show kubernetes nodes**
2014-09-12 22:53:32 +00:00
2015-07-19 15:53:44 +00:00
Run the following on the kube-master:
```sh
kubectl get nodes
```
**Show services running on masters and nodes**
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```sh
2014-09-12 22:53:32 +00:00
systemctl | grep -i kube
```
2015-07-19 15:53:44 +00:00
**Show firewall rules on the masters and nodes**
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```sh
2014-09-12 22:53:32 +00:00
iptables -nvL
```
2015-07-19 15:53:44 +00:00
**Create /tmp/apache.json on the master with the following contents and deploy pod**
2014-09-12 22:53:32 +00:00
2015-07-19 15:53:44 +00:00
```json
2014-09-12 22:53:32 +00:00
{
"kind": "Pod",
2015-06-05 19:47:15 +00:00
"apiVersion": "v1",
2015-05-28 22:43:09 +00:00
"metadata": {
"name": "fedoraapache",
"labels": {
"name": "fedoraapache"
2014-09-12 22:53:32 +00:00
}
},
2015-05-28 22:43:09 +00:00
"spec": {
"containers": [
{
"name": "fedoraapache",
"image": "fedora/apache",
"ports": [
{
"hostPort": 80,
"containerPort": 80
}
]
}
]
2014-09-12 22:53:32 +00:00
}
}
2015-07-19 15:53:44 +00:00
```
2015-03-24 02:17:28 +00:00
2015-07-19 15:53:44 +00:00
```sh
kubectl create -f /tmp/apache.json
2014-09-12 22:53:32 +00:00
```
2015-07-19 15:53:44 +00:00
**Check where the pod was created**
2014-10-28 22:57:07 +00:00
2015-07-19 02:01:59 +00:00
```sh
2015-03-24 02:17:28 +00:00
kubectl get pods
2014-10-28 22:57:07 +00:00
```
2015-07-19 15:53:44 +00:00
**Check Docker status on nodes**
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```sh
2014-09-12 22:53:32 +00:00
docker ps
docker images
```
2015-07-19 15:53:44 +00:00
**After the pod is 'Running' Check web server access on the node**
2014-09-12 22:53:32 +00:00
2015-07-19 02:01:59 +00:00
```sh
2014-09-12 22:53:32 +00:00
curl http://localhost
```
2015-03-24 02:17:28 +00:00
2015-04-09 17:54:14 +00:00
That's it !
2015-05-14 22:12:45 +00:00
2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-05-14 22:12:45 +00:00
[![Analytics ](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/getting-started-guides/fedora/fedora_ansible_config.md?pixel )]()
2015-07-14 00:13:09 +00:00
<!-- END MUNGE: GENERATED_ANALYTICS -->