k3s/docs/getting-started-guides/fedora/fedora_ansible_config.md

268 lines
6.9 KiB
Markdown
Raw Normal View History

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.
<strong>
The latest 1.0.x release of this document can be found
[here](http://releases.k8s.io/release-1.0/docs/getting-started-guides/fedora/fedora_ansible_config.md).
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 -->
Configuring Kubernetes on [Fedora](http://fedoraproject.org) via [Ansible](http://www.ansible.com/home)
-------------------------------------------------------------------------------------------------------
Configuring Kubernetes on Fedora via Ansible offers a simple way to quickly create a clustered environment with little effort.
**Table of Contents**
- [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)
- [Setting up the cluster](#setting-up-the-cluster)
- [Testing and using your new cluster](#testing-and-using-your-new-cluster)
2015-07-17 22:35:41 +00:00
## Prerequisites
2015-07-19 15:53:44 +00:00
1. Host able to run ansible and able to clone the following repo: [kubernetes](https://github.com/GoogleCloudPlatform/kubernetes.git)
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
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
## 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:
```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
```
2015-07-19 15:53:44 +00:00
**Make sure your local machine has**
2015-07-19 15:53:44 +00:00
- ansible (must be 1.9.0+)
- git
- python-netaddr
2015-07-19 15:53:44 +00:00
If not
```sh
2015-07-19 15:53:44 +00:00
yum install -y ansible git python-netaddr
```
**Now clone down the Kubernetes repository**
2015-07-19 15:53:44 +00:00
```sh
git clone https://github.com/GoogleCloudPlatform/kubernetes.git
cd kubernetes/contrib/ansible
```
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-07-19 15:53:44 +00:00
Get the IP addresses from the master and nodes. Add those to the `~/kubernetes/contrib/ansible/inventory` file on the host running Ansible.
```console
[masters]
2015-07-19 15:53:44 +00:00
kube-master.example.com
[etcd]
2015-07-19 15:53:44 +00:00
kube-master.example.com
2015-07-19 15:53:44 +00:00
[nodes]
kube-node-01.example.com
kube-node-02.example.com
```
2015-07-19 15:53:44 +00:00
## Setting up ansible access to your nodes
2015-07-19 15:53:44 +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 `~/kubernetes/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...
*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-07-19 15:53:44 +00:00
edit: ~/kubernetes/contrib/ansible/group_vars/all.yml
```yaml
2014-10-28 22:57:07 +00:00
ansible_ssh_user: root
```
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
```sh
2015-07-19 15:53:44 +00:00
ssh-keygen
```
2015-07-19 15:53:44 +00:00
Copy the ssh public key to **all** nodes in the cluster
```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
```
2015-07-19 15:53:44 +00:00
## Setting up the cluster
2014-10-28 22:57:07 +00:00
2015-07-19 15:53:44 +00:00
Although the default value of variables in `~/kubernetes/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-07-19 15:53:44 +00:00
edit: ~/kubernetes/contrib/ansible/group_vars/all.yml
2014-10-28 22:57:07 +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**
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-07-19 15:53:44 +00:00
**Managing add on services in your cluster**
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-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-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
```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!**
This will finally setup your whole Kubernetes cluster for you.
```sh
2015-07-19 15:53:44 +00:00
cd ~/kubernetes/contrib/ansible/
./setup.sh
```
2014-10-28 22:57:07 +00:00
## Testing and using your new cluster
That's all there is to it. It's really that easy. At this point you should have a functioning Kubernetes cluster.
2015-07-19 15:53:44 +00:00
**Show kubernets nodes**
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**
```sh
systemctl | grep -i kube
```
2015-07-19 15:53:44 +00:00
**Show firewall rules on the masters and nodes**
```sh
iptables -nvL
```
2015-07-19 15:53:44 +00:00
**Create /tmp/apache.json on the master with the following contents and deploy pod**
2015-07-19 15:53:44 +00:00
```json
{
"kind": "Pod",
2015-06-05 19:47:15 +00:00
"apiVersion": "v1",
"metadata": {
"name": "fedoraapache",
"labels": {
"name": "fedoraapache"
}
},
"spec": {
"containers": [
{
"name": "fedoraapache",
"image": "fedora/apache",
"ports": [
{
"hostPort": 80,
"containerPort": 80
}
]
}
]
}
}
2015-07-19 15:53:44 +00:00
```
2015-07-19 15:53:44 +00:00
```sh
kubectl create -f /tmp/apache.json
```
2015-07-19 15:53:44 +00:00
**Check where the pod was created**
2014-10-28 22:57:07 +00:00
```sh
kubectl get pods
2014-10-28 22:57:07 +00:00
```
2015-07-19 15:53:44 +00:00
**Check Docker status on nodes**
```sh
docker ps
docker images
```
2015-07-19 15:53:44 +00:00
**After the pod is 'Running' Check web server access on the node**
```sh
curl http://localhost
```
2015-04-09 17:54:14 +00:00
That's it !
2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![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 -->