Kubespray and Ansible, how to seperate config(ie inventory and other config files)

564 views Asked by At

First, I'm a complete ansible playbook noob. I'm busy trying to understand a clutser at my workplace. I tried following the readme's quick start guide whilst also following my companies kubespray fork. One thing that is really bothering me right now, is that configuration for our personal cluster is littered throughout the entire fork. Is there no way to separate my personal config files for the cluster from the kubespray repository? My idea is that I have a kubespray directory which is a fork, or master of the kubespray repository and when running 'kubespray' I supply my cluster's config to kubespray. Because currently I can't see how this is a clean and manageable way to maintain cluster resources with commits while also trying to update kubespray when I want to apply a new version. the current process seems like a utter mess!

1

There are 1 answers

0
Jared Rieger On

So I ended up finding a nice solution that extrapolated away custom personal configuration from the kubespray repo. I assume this would actually be pretty obvious to seasoned Ansible users but the structure is as followed.

.
├── README.md
├── bin
├── docs
├── inventory
│   └── prod
│       ├── group_vars
│       │   ├── all
│       │   │   ├── all.yml
│       │   │   ├── azure.yml
│       │   │   ├── coreos.yml
│       │   │   ├── docker.yml
│       │   │   ├── oci.yml
│       │   │   └── openstack.yml
│       │   ├── balance.yml
│       │   ├── etcd.yml
│       │   └── k8s-cluster
│       │       ├── addons.yml
│       │       ├── ip.yml
│       │       ├── k8s-cluster.yml
│       │       ├── k8s-net-calico.yml
│       │       ├── k8s-net-canal.yml
│       │       ├── k8s-net-cilium.yml
│       │       ├── k8s-net-contiv.yml
│       │       ├── k8s-net-flannel.yml
│       │       ├── k8s-net-kube-router.yml
│       │       └── k8s-net-weave.yml
│       └── hosts.ini
└── kubespray

Now within the main dir you can run your kubespray commands like so

ansible-playbook \
        $(pwd)/kubespray/scale.yml \
        --inventory $(pwd)/inventory/prod/hosts.ini \
        --user root \
        --become \
        --become-user=root \
        --limit=$node \
        --extra-vars 'ansible_python_interpreter=/usr/bin/python3' \
        --flush-cache

The great thing about this structure is that you can now use git to track your changes to your infrastructure only and not having to worry about meddling with the files within Kubespray. Plus by having kubespray as a gitsubmodule you can also track the different versions with the configuration of servers. just general git goodness.

Anyway, I hope someone finds this useful. I've been using for a couple of months and found it far cleaner than having your configuration within the kubespray module.