Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update init #8

Merged
merged 7 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ profile: null
# ```
skip_list:
- skip_this_tag
- command-instead-of-shell
- no-changed-when
- loop-var-prefix[missing]
###
# Define required Ansible's variables to satisfy syntax check
# extra_vars:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
.sphinx/bin/pipenv install --dev
.sphinx/bin/pipenv install --categories docs
- name: Build artifact
run: .venv/bin/sphinx-build -a -E . deploy
run: .venv/bin/sphinx-build -a -b html -E . deploy
- name: Upload artifact
uses: actions/upload-pages-artifact@main
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ node_modules
package-lock.json
package.json
roles/reset/files/*.reset.md
roles/join/files/join.md
roles/init/files/admin.conf
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ gitpython = "*"
loguru = "*"
pipenv = "*"
redis = "*"
sphinxcontrib-yaml = "*"

[dev-packages]
ansible-lint = "*"
molecule = "*"
pytest = "*"
pytest-cov = "*"
Expand Down
383 changes: 377 additions & 6 deletions Pipfile.lock

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions cicd.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ title: CI/CD

Stay away from zero days with Dependabot.

```{autoyaml} .github/dependabot.yml
```{literalinclude} /.github/dependabot.yml
:language: yaml
```

## Workflows
Expand All @@ -26,21 +27,24 @@ run a lot of pipelines for free.

The CodeQL workflow provided by GitHub is actually pretty good also.

```{autoyaml} .github/workflows/codeql.yml
```{literalinclude} .github/workflows/codeql.yml
:language: yaml
```

### pages

Build and deploy the GitHub Pages docs.

```{autoyaml} .github/workflows/pages.yml
```{literalinclude} .github/workflows/pages.yml
:language: yaml
```

### shell

And ShellCheck never hurt anybody either.

```{autoyaml} .github/workflows/shell.yml
```{literalinclude} .github/workflows/shell.yml
:language: yaml
```

## Lint
Expand All @@ -49,5 +53,6 @@ This is the configuration for the various lint tools used here.

### ansible-lint

```{autoyaml} .ansible-lint
```{literalinclude} .ansible-lint
:language: yaml
```
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def get_version():
exclude_patterns = [
"_build",
"Thumbs.db",
'roles/join/files/join.md',
".DS_Store",
".pytest_cache/*",
".tox/*",
'roles/reset/files/kcp01.breeze-blocks.net.reset.md/kcp01.breeze-blocks.net/root/reset.md',
".venv/*",
]
extensions = [
Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ title: Ansible Bare Metal K8S
```{rubric} site.yml
```

```{autoyaml} ./site.yml
```{literalinclude} ./site.yml
```

### Roles
Expand Down
12 changes: 0 additions & 12 deletions roles/init/files/reset.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions roles/init/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ More information about the process for HA setup is available

A handy tool for switching k8s contexts is called
[kubie](https://github.com/sbstp/kubie).

## Tasks

```{literalinclude} /roles/init/tasks/main.yml
:language: yaml
```

```{sectionauthor} Xander Harris <[email protected]>
```
69 changes: 54 additions & 15 deletions roles/init/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
###
# ```{rubric} Prep for Kubeadm
# ```
# ---
# Prepare the first control plane for init.
#
# ```{literalinclude} /roles/init/tasks/main.yml
# :language: yaml
# :start-at: "- name: Create kube group\n"
# :end-at: " mode: ugo+rw\n"
# ```
- name: Create kube group
ansible.builtin.group:
name: kube
Expand All @@ -20,13 +31,9 @@
ansible.builtin.file:
dest: /etc/kubeadm/init.token
state: absent

- name: Reset existing cluster
- name: Generate a boostrap token
ansible.builtin.shell:
chdir: /etc/kubeadm
cmd: >-
kubeadm token generate > init.token && cat init.token
creates: /etc/kubeadm/init.token
cmd: kubeadm token generate
register: token_out
- name: Template token init config
ansible.builtin.template:
Expand All @@ -35,12 +42,44 @@
owner: kube
group: kube
mode: ugo+rw
# - name: Init new cluster
# ansible.builtin.command:
# chdir: /etc/kubeadm
# cmd: kubeadm init --config init.yaml
# creates: /etc/kubernetes/admin.conf
# register: init_result
# - name: Debug
# ansible.builtin.debug:
# var: init_result
###
# ```{rubric} Init 1
# ```
# ---
# Run the command to initialize the first control plane.
#
# ```{literalinclude} /roles/init/tasks/main.yml
# :language: yaml
# :start-at: "- name: Init new cluster\n"
# ```
- name: Init new cluster
ansible.builtin.shell:
chdir: /etc/kubeadm
cmd: kubeadm init --config init.yaml --upload-certs &> /root/join.md
creates: /etc/kubernetes/admin.conf
register: init_result
- name: Debug
ansible.builtin.debug:
var: init_result
- name: Pull stored output from host
ansible.builtin.fetch:
src: /root/join.md
dest: roles/join/files/
flat: true
- name: Pull admin conf from remote
ansible.builtin.fetch:
src: /etc/kubernetes/admin.conf
dest: roles/init/files/
flat: true
- name: Copy admin conf back to remote
ansible.builtin.copy:
src: roles/init/files/admin.conf
dest: "{{ item.path }}"
owner: "{{ item.owner }}"
group: kube
mode: u+rw,go-rwx
loop:
- path: /root/.kube/config
owner: root
- path: "/home/{{ kcp_nonroot }}/.kube/config"
owner: "{{ kcp_nonroot }}"
6 changes: 3 additions & 3 deletions roles/init/templates/init.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ clusterName: breeze-blocks
controllerManager: {}
controlPlaneEndpoint: {{ kcp_aa }}
dns: {}
etcd:
local:
dataDir: /var/lib/etcd
# etcd:
# local:
# dataDir: /var/lib/etcd
imageRepository: registry.k8s.io
kind: ClusterConfiguration
kubernetesVersion: 1.30.0
Expand Down
Empty file removed roles/init/templates/join.yaml
Empty file.
4 changes: 4 additions & 0 deletions roles/join/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Output nothing
ansible.builtin.debug:
msg: "nothing here"
3 changes: 2 additions & 1 deletion roles/reset/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ title: Reset Cluster

## Reset Role Usage

```{autoyaml} roles/reset/tasks/main.yml
```{literalinclude} /roles/reset/tasks/main.yml
:language: yaml
```

```{index} role; reset
Expand Down
8 changes: 4 additions & 4 deletions roles/reset/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- name: Show output
ansible.builtin.debug:
var: reset_out
- name: Pull stored output from hosts
ansible.builtin.fetch:
src: /root/reset.md
dest: "roles/reset/files/{{ inventory_hostname }}.reset.md"
- name: Drop reset output
ansible.builtin.file:
dest: /root/reset.md
state: absent
11 changes: 11 additions & 0 deletions site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
# ```
# ---
# This playbook defines the primary site deployment code for this repository.
#
# ```{literalinclude} /site.yml
# :language: yaml
# ```
- name: Reset Kubernetes Control Planes
hosts: kcp
become: true
roles:
- role: reset
tags:
- reset
- name: Initialize the first control plane
hosts: kcp01
become: true
roles:
- role: init
tags:
- init