summaryrefslogtreecommitdiffstats
path: root/roles/kube_nfs_volumes/README.md
blob: 8cf7c0cd4e4867c1b02af3d4ce9b1c6bccf4f0a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# kube_nfs_volumes

This role is useful to export disks as set of Kubernetes persistent volumes.
It does so by partitioning the disks, creating ext4 filesystem on each
partition, mounting the partitions, exporting the mounts via NFS and adding
these NFS shares as NFS persistent volumes to existing Kubernetes installation.

All partitions on given disks are used as the persistent volumes, including
already existing partitions! There should be no other data (such as operating
system) on the disks!

## Requirements

* Ansible 2.2
* Running Kubernetes with NFS persistent volume support (on a remote machine).
* Works only on RHEL/Fedora-like distros.

## Role Variables

```
# Options of NFS exports.
nfs_export_options: "*(rw,no_root_squash,insecure,no_subtree_check)"

# Directory, where the created partitions should be mounted. They will be
# mounted as <mount_dir>/sda1 etc.
mount_dir: /exports

# Comma-separated list of disks to partition.
# This role always assumes that all partitions on these disks are used as
# physical volumes.
disks: /dev/sdb,/dev/sdc

# Whether to re-partition already partitioned disks.
# Even though the disks won't get repartitioned on 'false', all existing
# partitions on the disk are exported via NFS as physical volumes!
force: false

# Specification of size of partitions to create. See library/partitionpool.py
# for details.
sizes: 100M

# URL of Kubernetes API server, incl. port.
kubernetes_url: https://10.245.1.2:6443

# Token to use for authentication to the API server
kubernetes_token: tJdce6Fn3cL1112YoIJ5m2exzAbzcPZX

# API Version to use for kubernetes
kube_api_version: v1
```

## Dependencies

None

## Example Playbook

With this playbook, `/dev/sdb` is partitioned into 100MiB partitions, all of
them are mounted into `/exports/sdb<N>` directory and all these directories
are exported via NFS and added as physical volumes to Kubernetes running at
`https://10.245.1.2:6443`.

    - hosts: servers
      roles:
        - role: kube_nfs_volumes
          disks: "/dev/sdb"
          sizes: 100M
          kubernetes_url: https://10.245.1.2:6443
          kubernetes_token: tJdce6Fn3cL1112YoIJ5m2exzAbzcPZX

See library/partitionpool.py for details how `sizes` parameter can be used
to create partitions of various sizes.

## Full example
Let's say there are two machines, 10.0.0.1 and 10.0.0.2, that we want to use as
NFS servers for our Kubernetes cluster, running Kubernetes public API at
https://10.245.1.2:6443.

Both servers have three 1 TB disks, /dev/sda for the system and /dev/sdb and
/dev/sdc to be partitioned. We want to split the data disks into 5, 10 and
20 GiB partitions so that 10% of the total capacity is in 5 GiB partitions, 40%
in 10 GiB and 50% in 20 GiB partitions.

That means, each data disk will have 20x 5 GiB, 40x 10 GiB and 25x 20 GiB
partitions.

* Create an `inventory` file:
    ```
    [nfsservers]
    10.0.0.1
    10.0.0.2
    ```

* Create an ansible playbook, say `setupnfs.yaml`:
    ```
    - hosts: nfsservers
      become: yes
      roles:
         - role: kube_nfs_volumes
           disks: "/dev/sdb,/dev/sdc"
           sizes: 5G:10,10G:40,20G:50
           force: no
           kubernetes_url: https://10.245.1.2:6443
           kubernetes_token: tJdce6Fn3cL1112YoIJ5m2exzAbzcPZX
    ```

* Run the playbook:
    ```
    ansible-playbook -i inventory setupnfs.yml
    ```

## License

Apache 2.0