Skip to content

Commit

Permalink
Feature/kubeblocks (#65)
Browse files Browse the repository at this point in the history
* prepare.sh

* test-environment

* cluster_admin gets kube config

* kubeblocks

* roles
  • Loading branch information
bbaassssiiee authored Dec 18, 2024
1 parent 95c7ef2 commit c60ab7b
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 52 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Run the included setup scripts to install Ansible in a python virtualenv, and in

```bash
source ansible.sh
./galaxy.sh
./prepare.sh
```
### 3. Configure Inventory

Expand All @@ -43,9 +43,11 @@ Edit the `inventory/yourcluster/group_vars/all/vars.yml` to select features in y

For detailed information, refer to KUBESPRAY.md or [https://kubespray.io/#/](https://kubespray.io/#/).

Run the host-initialization.yml playbook to prep the machines.

### 4. Manage the Cluster

Run the cluster playbook to deploy the cluster:
Run the cluster.yml playbook to deploy the cluster:

```bash
./cluster.yml -i inventory/mycluster/hosts --become -K
Expand All @@ -59,11 +61,13 @@ Run the reset playbook to delete the cluster:

### Post-Deployment

After deployment, verify the cluster status:
NOTE: `~/.kube/config` is copied to all hosts for convenience. Run the cluster.yml playbook with `--skip-tags kube_config` to avoid that.
After deployment, run the kube-config.yml playbook.
NOTE: `~/.kube/config` is copied to the user running that playbook, and the `cluster_admin`, if defined, else to the `root` user too.

Use `k9s` as tool to work with the cluster.
```bash
kubectl get nodes
# Start K9s in readonly mode - with all modification commands disabled
k9s --readonly
```

### Troubleshooting
Expand Down
2 changes: 1 addition & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ roles_path = roles

; dev and test are available for Vagrant by setting the STAGE environment variable.
; set inventory here, or on the command-line when running Ansible.
inventory = inventory/dev/hosts
inventory = inventory/test/hosts

# Disabled json fact caching for Semaphore
# https://github.com/ansible/ansible/issues/68425
Expand Down
35 changes: 0 additions & 35 deletions config.yml

This file was deleted.

File renamed without changes.
67 changes: 67 additions & 0 deletions kube-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env ansible-playbook
---

- name: Kube config on controller
hosts: kube_control_plane
tags: [kube_config]
gather_facts: true
tasks:
- name: Gather facts
become: false
ansible.builtin.setup:
gather_subset: platform

- name: Set local user
become: false
ansible.builtin.set_fact:
local_user: "{{ lookup('env', 'USER') }}"

- name: Create local config dirs
delegate_to: localhost
become: true
ansible.builtin.file:
path: "~{{ local_user }}/.kube"
owner: "{{ local_user }}"
state: directory
mode: '0700'

- name: Fetch kube config from master
when: inventory_hostname in groups['kube_control_plane']
become: true
ansible.builtin.fetch:
src: /etc/kubernetes/admin.conf
dest: "~{{ local_user }}/.kube/config"
owner: "{{ local_user }}"
mode: '0600'
flat: true

- name: Configure k8s master
delegate_to: localhost
become: true
ansible.builtin.lineinfile:
path: "~{{ local_user }}/.kube/config"
regexp: ' server.*6443$'
line: " server: https://{{ groups['kube_control_plane'][0] }}:6443"
state: present
mode: '0600'

- name: Create local config dirs
delegate_to: localhost
become: true
ansible.builtin.file:
path: "~{{ cluster_admin | default('root') }}/.kube"
owner: "{{ cluster_admin | default('root') }}"
group: "{{ cluster_admin | default('root') }}"
state: directory
mode: '0700'

- name: Copy kube config to cluster
delegate_to: localhost
become: true
ansible.builtin.copy:
remote_src: true
src: "~{{ local_user }}/.kube/config"
dest: "~{{ cluster_admin | default('root') }}/.kube/"
owner: "{{ cluster_admin | default('root') }}"
group: "{{ cluster_admin | default('root') }}"
mode: '0600'
15 changes: 4 additions & 11 deletions kubeblocks.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ansible-playbook
---
# ~/.kube/config should be valid
- name: Manage KubeBlocks
Expand All @@ -8,14 +9,6 @@
ansible.builtin.include_role:
name: bbaassssiiee.kubeblocks

- name: Install KubeBlocks add-ons
when:
- kubeblocks_add_ons|length >= 1
ansible.builtin.include_tasks: addons.yml
loop: "{{ kubeblocks_add_ons }}"

- name: Install KubeBlock clusters
when:
- kubeblocks_clusters|length >= 1
ansible.builtin.include_tasks: clusters.yml
loop: "{{ kubeblocks_clusters }}"
- name: Configure KubeBlocks
ansible.builtin.include_role:
name: clusterlust.kubeblocks
1 change: 1 addition & 0 deletions galaxy.sh → prepare.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
ansible-galaxy install -r roles/requirements.yml
ansible-galaxy collection install -r collections/requirements.yml
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions roles/clusterlust.kubeblocks/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Install KubeBlocks add-ons
when:
- kubeblocks_add_ons|length >= 1
ansible.builtin.include_tasks: addons.yml
loop: "{{ kubeblocks_add_ons }}"

- name: Install KubeBlock clusters
when:
- kubeblocks_clusters|length >= 1
ansible.builtin.include_tasks: clusters.yml
loop: "{{ kubeblocks_clusters }}"

0 comments on commit c60ab7b

Please sign in to comment.