Compare commits

...

136 Commits

Author SHA1 Message Date
Jon
0b84d1bc0e Merge branch 'automated-tasks' into 'development'
chore(gitlab-ci): Automated update of git sub-module

See merge request nofusscomputing/projects/ansible/collections/kubernetes!83
2025-02-26 13:20:51 +00:00
c8a1f60a9e chore(git): updated submodule gitlab-ci
Automation Data:
{
    "branch": "development",
    "current_commit": "6f8dfcba0b25313b59bc17b4c99d674fcedd207a)",
    "name": "gitlab-ci",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/gitlab-ci",
    "remote_head": "224ef831571458ad433a0143eec00df0f7e8b409)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/projects/gitlab-ci.git"
}

Changes: Submodule path gitlab-ci: checked out 224ef831571458ad433a0143eec00df0f7e8b409

MR !83
2025-02-26 13:08:54 +00:00
Jon
a790f5c60c Merge branch 'automated-tasks' into 'development'
chore(gitlab-ci): Automated update of git sub-module

See merge request nofusscomputing/projects/ansible/collections/kubernetes!81
2024-11-03 19:37:38 +00:00
0ebb28c978 chore(git): updated submodule gitlab-ci
Automation Data:
{
    "branch": "development",
    "current_commit": "58ffcabbfb503af3e57d9cb3ab43931b23dc4cd8)",
    "name": "gitlab-ci",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/gitlab-ci",
    "remote_head": "6f8dfcba0b25313b59bc17b4c99d674fcedd207a)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/projects/gitlab-ci.git"
}

Changes: Submodule path gitlab-ci: checked out 6f8dfcba0b25313b59bc17b4c99d674fcedd207a

MR !81
2024-08-19 07:24:43 +00:00
e0ee4ba249 chore(git): updated submodule gitlab-ci
Automation Data:
{
    "branch": "development",
    "current_commit": "673441f83a7d943434252ee23899e3572cdfb141)",
    "name": "gitlab-ci",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/gitlab-ci",
    "remote_head": "58ffcabbfb503af3e57d9cb3ab43931b23dc4cd8)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/projects/gitlab-ci.git"
}

Changes: Submodule path gitlab-ci: checked out 58ffcabbfb503af3e57d9cb3ab43931b23dc4cd8

MR !81
2024-08-01 06:08:19 +00:00
a6aeac42c8 build: bump version 1.13.1 -> 1.13.2
!77
2024-07-30 05:30:59 +00:00
Jon
ce8143f52d fix(nfc_kubernetes): correct logic for prime node to always be labeled prime
useful for setting up single node where if all nodes off except prime, targeting can be done

!77 !78 !79 !80 nofusscomputing/infrastructure/configuration-management/project-production!58 nofusscomputing/infrastructure/configuration-management/inventory-infrastructure!4 nofusscomputing/infrastructure/configuration-management/templates-production!28
2024-07-30 14:47:26 +09:30
6581056bc9 build: bump version 1.13.0 -> 1.13.1
!77
2024-07-28 08:11:42 +00:00
Jon
c204539b67 fix(nfc_kubernetes): prime node to always be labeled prime
useful for setting up single node where if all nodes off except prime, targeting can be done

!77 !78 !79 nofusscomputing/infrastructure/configuration-management/project-production!58 nofusscomputing/infrastructure/configuration-management/inventory-infrastructure!4 nofusscomputing/infrastructure/configuration-management/templates-production!28
2024-07-28 17:27:52 +09:30
06f44f5c3b build: bump version 1.12.0 -> 1.13.0
!77
2024-07-28 06:36:20 +00:00
Jon
9f3fcdc5e3 Merge branch 'node-labels-taints' into 'development'
feat(nfc_kubernetes): ability to add node labels and taints

See merge request nofusscomputing/projects/ansible/collections/kubernetes!77
2024-07-28 06:23:02 +00:00
Jon
3c06647637 feat(nfc_kubernetes): prime node to always be labeled prime
useful for setting up single node where if all nodes off except prime, targeting can be done

!77 nofusscomputing/infrastructure/configuration-management/project-production!58 nofusscomputing/infrastructure/configuration-management/inventory-infrastructure!4 nofusscomputing/infrastructure/configuration-management/templates-production!28
2024-07-28 15:40:24 +09:30
Jon
6d26e2e0cf feat(nfc_kubernetes): ability to add node labels and taints
!77 nofusscomputing/infrastructure/configuration-management/project-production!58 nofusscomputing/infrastructure/configuration-management/inventory-infrastructure!4 nofusscomputing/infrastructure/configuration-management/templates-production!28
2024-07-28 15:29:46 +09:30
b47b868f43 build: bump version 1.11.0 -> 1.12.0
!75
2024-07-08 07:48:01 +00:00
Jon
f3f2769f0a Merge branch 'fixes' into 'development'
fix(kebernetes): Apply fixes listed in issues

Closes #33 and #32

See merge request nofusscomputing/projects/ansible/collections/kubernetes!75
2024-07-08 02:02:29 +00:00
cba13dd8a3 fix(kubernetes_roles): conditional checks for prime
required so that config not applied to workers

!75
2024-07-08 00:46:06 +00:00
425e05de37 fix(kubernetes_roles): conditional checks for prime
required so that config not applied to workers

!75
2024-07-08 00:45:55 +00:00
cf63ec5543 fix(kubernetes_roles): conditional checks for prime
required so that config not applied to workers

!75
2024-07-08 00:45:42 +00:00
115755ad54 fix(kubernetes_roles): clean up white space
!75
2024-07-08 00:44:15 +00:00
6893164f90 fix(kubernetes_roles): clean up white space
!75
2024-07-08 00:44:05 +00:00
6275dde9e3 fix(kubernetes_roles): clean up white space
!75
2024-07-08 00:43:51 +00:00
98b6442bf8 fix(kubernetes_roles): clean up white space
!75
2024-07-08 00:43:33 +00:00
202e92a90b fix(kubernetes_role): delete leftover ]
this was a leftover from a copy and paste

!75
2024-07-07 14:33:45 +09:30
860addad4d fix(kubernetes_role): Change "https://" + hostvars[ns.prime_name].ansible_host + ":6443" -> "https://" + ns.prime_name.ansible_host + ":6443"
!75
2024-07-07 14:23:44 +09:30
8c1223769d fix(kubernetes_role): get prime hostname
required to set https address

!75
2024-07-07 14:11:30 +09:30
6bd8d27cfd fix(kubernetes_role): set server var -> "https://" + hostvars[nfc_role_kubernetes_node_prime].ansible_host + ":6443"
!75
2024-07-07 10:35:03 +09:30
a8ddcad1a0 fix(kubernetes_role): remove not nfc_role_kubernetes_cluster_upgraded | default(true) | bool section
Does not appear to acomplish what I was after

!75
2024-07-06 14:29:41 +09:30
536bab4ce2 fix(kubernetes_role): undo previous change
tasks did not run

!75
2024-07-06 14:08:51 +09:30
8217889910 test(kubernetes_role): set not nfc_role_kubernetes_cluster_upgraded | default(false | bool -> not nfc_role_kubernetes_cluster_upgraded | default(true) | bool
Testing to set node as a prime

!75
2024-07-06 13:49:52 +09:30
d59f20077e test(kubernetes_role): set prime default value to true
!74
2024-07-06 12:33:13 +09:30
23808704ae fix(kubernetes_role): remove commented out section
Not required

!74
2024-07-06 11:53:31 +09:30
55cc007575 fix(kubernetes_roles): use inventory_hostname
!74
2024-07-05 12:33:42 +09:30
044c914617 feat(kubernetes_role): nfc_role_kubernetes_prime cast type to bool
needs to check if type is a boolean

!74
2024-07-05 12:16:47 +09:30
2d5eb7c375 fix(kubernetes_roles): update cmd for setting ip6tables
!74
2024-07-04 18:10:18 +09:30
4d51d3ca00 fix(kubernetes_roles): update variable nfc_role_kubernetes_prime | default(false) | boolean -> nfc_role_kubernetes_prime !=false
test failed with result could not load boolean

!74
2024-07-04 17:21:05 +09:30
14a2cbed98 fix(kubernetes_role): set variable prime_hostname
!74
2024-07-04 17:10:40 +09:30
a2580f9328 fix(kubernetes_roles): update variable nfc_role_kubernetes_prime type to boolean
!74
2024-07-04 16:42:00 +09:30
28c4e3bbca feat(kubernetes_role): set var nfc_role_kubernetes_prime type boolean
!74 fixes #33
2024-07-04 15:24:45 +09:30
576ab623d8 fix(kubernetes_role): update var kubernetes_config.cluster.prime.name -> nfc_role_kubernetes_prime
variable is depreciated

!74
2024-07-04 15:03:16 +09:30
f5bba112cf feat(kubernetes_role): set ip6tables to legacy mode
!74 fixes #32
2024-07-04 14:41:06 +09:30
5a188407fe Merge branch 'automated-tasks' into 'development'
chore(website-template): Automated update of git sub-module

See merge request nofusscomputing/projects/ansible/collections/kubernetes!73
2024-06-30 18:14:29 +00:00
cb6211862c chore(git): updated submodule website-template
Automation Data:
{
    "branch": "development",
    "current_commit": "92c4b16a14524e7b5b18171d4e21b72676c36fbf)",
    "name": "website-template",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/website-template",
    "remote_head": "8735f623dc5e1d9c9e46e50db03b4c41cb3d1efd)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/infrastructure/website-template.git"
}

Changes: Submodule path website-template: checked out 8735f623dc5e1d9c9e46e50db03b4c41cb3d1efd

MR !73
2024-06-30 18:03:32 +00:00
88e5f73b33 Merge branch 'automated-tasks' into 'development'
chore(gitlab-ci): Automated update of git sub-module

See merge request nofusscomputing/projects/ansible/collections/kubernetes!72
2024-06-30 18:00:03 +00:00
870dfcbb81 chore(git): updated submodule website-template
Automation Data:
{
    "branch": "development",
    "current_commit": "f5a82d3604faca56756eec91acee28ff89defd1d)",
    "name": "website-template",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/website-template",
    "remote_head": "92c4b16a14524e7b5b18171d4e21b72676c36fbf)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/infrastructure/website-template.git"
}

Changes: Submodule path website-template: checked out 92c4b16a14524e7b5b18171d4e21b72676c36fbf

MR !72
2024-06-30 17:48:08 +00:00
edb2ef2409 chore(git): updated submodule gitlab-ci
Automation Data:
{
    "branch": "development",
    "current_commit": "a24f352ca3d82b8d0f02f5db20173fe2c3f71a4a)",
    "name": "gitlab-ci",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/gitlab-ci",
    "remote_head": "673441f83a7d943434252ee23899e3572cdfb141)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/projects/gitlab-ci.git"
}

Changes: Submodule path gitlab-ci: checked out 673441f83a7d943434252ee23899e3572cdfb141

MR !72
2024-06-30 17:46:00 +00:00
49077e1088 build: bump version 1.10.3 -> 1.11.0
!71 nofusscomputing/projects/ansible/collections/firewall
2024-06-27 15:25:12 +00:00
Jon
ea3547a48f feat(firewall): update collection nfc_firewall 1.1.0 -> 1.1.1
!71 nofusscomputing/projects/ansible/collections/firewall!27
2024-06-28 00:40:27 +09:30
c87ed1646a build: bump version 1.10.2 -> 1.10.3
!69
2024-06-27 07:39:53 +00:00
Jon
25496d1f55 Merge branch '31-fix-ipv6-check' into 'development'
fix: kubernetes install failes when host with ipv6 disabled

Closes #31

See merge request nofusscomputing/projects/ansible/collections/kubernetes!69
2024-06-27 07:26:27 +00:00
Jon
b0d9279535 fix(install): ensure ipv6 is installed before attempting to disable
!69 fixes #31
2024-06-27 16:43:33 +09:30
7905f881fe build: bump version 1.10.1 -> 1.10.2
!68 nofusscomputing/projects/ansible/execution_environment
2024-05-03 20:38:59 +00:00
Jon
5ee0782993 fix(nfc_kubernetes): set default for var so task 'Copy Template' when clause doesn't fail task with undefined var
!68 nofusscomputing/projects/ansible/execution_environment!256
2024-05-04 05:56:00 +09:30
aeb1bcc048 build: bump version 1.10.0 -> 1.10.1
!67
2024-05-03 19:27:15 +00:00
Jon
bcc870a87c fix(nfc_kubernetes): set default for var so when clause doesn't fail task with undefined var
!67
2024-05-04 04:43:24 +09:30
c2c0a9fe7d build: bump version 1.9.0 -> 1.10.0
!65
2024-05-03 18:33:42 +00:00
Jon
1f90af4eac Merge branch '28-29-logic-fixes' into 'development'
fix: logic

Closes #28 and #29

See merge request nofusscomputing/projects/ansible/collections/kubernetes!65
2024-05-03 18:20:28 +00:00
Jon
a01af004a7 ci(test): add two apt updates in an attempt to correct apt-key random errors
error is "Unknown error executing apt-key" and "GPG error: < repo> InRelease: Unknown error executing apt-key"

!65
2024-05-04 03:36:02 +09:30
Jon
e002ff3749 fix(nfc_kubernetes): correct 'Create Required directories' when logic
!65
2024-05-04 03:23:29 +09:30
Jon
ece10c7ee0 feat(nfc_kubernetes): new variable 'nfc_role_kubernetes_node_prime' to denote the hostname of the prime node
!65 fixes #28
2024-05-04 01:47:49 +09:30
Jon
cbd2ec7ef8 refactor(nfc_kubernetes): remove usage of prime node name over is_prime var
!65 #28
2024-05-04 01:47:49 +09:30
Jon
43ddb13bdd fix(nfc_kubernetes): only run tasks on master nodes
!65 #28
2024-05-04 01:47:49 +09:30
Jon
310d7a1c48 fix(nfc_kubernetes): only run tasks on prime node
!65 #28
2024-05-04 01:47:49 +09:30
Jon
2ebeb805e8 fix(nfc_kubernetes): ensure correct node type selection for installation
!65 fixes #29
2024-05-04 01:47:49 +09:30
0d0d1862cc build: bump version 1.8.1-a2 -> 1.9.0
!63
2024-05-03 13:10:33 +00:00
Jon
b4c06b9f91 feat(nfc_kubernetes): add debug out to k3s download on failure
!63
2024-05-03 22:27:39 +09:30
Jon
3d0dda7277 revert: "feat(nfc_kubernetes) build url and on use cast as string"
This reverts commit 9fa3b233a9.

The bug was within awx-core 2.16.1 as upgrading to 2.16.6 fixed the problem

!63 !61 nofusscomputing/projects/ansible/execution_environment!255 closes https://github.com/ansible/awx/issues/15161
2024-05-02 15:00:51 +09:30
1a11014420 build: bump version 1.8.1-a1 -> 1.8.1-a2
!64 https://github.com/ansible/awx/issues/15161
2024-05-02 01:44:21 +00:00
Jon
ad55d3e874 fix(nfc_kubernetes): cast url var as list
!64 https://github.com/ansible/awx/issues/15161
2024-05-02 11:01:02 +09:30
e0035d88df build: bump version 1.8.0 -> 1.8.1-a1
!64
2024-05-02 01:29:53 +00:00
Jon
52c4ee12fa Merge branch 'feat-workaround-15161' into 'development'
fix: workaround 15161

See merge request nofusscomputing/projects/ansible/collections/kubernetes!64
2024-05-02 01:27:52 +00:00
Jon
b4d5031b0a fix(nfc_kubernetes): correct url build to loop through all cpu arch
!64 https://github.com/ansible/awx/issues/15161
2024-05-02 10:45:58 +09:30
3cf2a2e169 build: bump version 1.7.2 -> 1.8.0
!61
2024-05-02 00:26:59 +00:00
Jon
358891e1cc Merge branch 'feat-workaround-15161' into 'development'
feat: workaround 15161

Closes #27

See merge request nofusscomputing/projects/ansible/collections/kubernetes!61
2024-05-02 00:20:25 +00:00
Jon
9fa3b233a9 feat(nfc_kubernetes): build url and on use cast as string
!61 https://github.com/ansible/awx/issues/15161 closes #27
2024-05-02 09:42:59 +09:30
9ec1ba4c51 build: bump version 1.7.1 -> 1.7.2
!59
2024-04-25 07:22:05 +00:00
Jon
bb707149f6 Merge branch '26-nfc_kubernetes-check-mode-support' into 'development'
fix: install fails in check mode

Closes #26

See merge request nofusscomputing/projects/ansible/collections/kubernetes!59
2024-04-25 07:09:32 +00:00
Jon
f622228493 ci(tests): correct so they are always available on all branches intended
!59
2024-04-25 16:27:38 +09:30
Jon
5efd9807f6 fix(nfc_kubernetes): adjust some tasks to run during checkmode
these tasks make no change and are required for checkmode to function as it's intended

!59 fixes #26
2024-04-25 16:24:48 +09:30
f09a71ef77 build: bump version 1.7.0 -> 1.7.1
!58
2024-04-24 03:23:27 +00:00
Jon
9d9cffb03a fix: add role readme
!58
2024-04-24 12:40:48 +09:30
50c89c9f00 build: bump version 1.6.0 -> 1.7.0
!56
2024-04-24 02:24:40 +00:00
Jon
325b0e51d0 Merge branch 'netbox_role' into 'development'
feat: Netbox role

See merge request nofusscomputing/projects/ansible/collections/kubernetes!56
2024-04-24 02:11:07 +00:00
Jon
1068223abd chore: add default mr template with linked items
!56
2024-04-24 11:27:28 +09:30
Jon
241c737647 feat(kubernetes_netbox): custom field bug work around
!56
2024-04-24 11:20:19 +09:30
Jon
33a40d0ba9 docs(navigation): add role kubernetes_netbox
!56
2024-04-24 11:19:31 +09:30
Jon
0ce3ed1245 fix(nfc_kubernetes): ensure install tasks run when job_tags specified
!56
2024-04-24 11:18:00 +09:30
Jon
0097556730 fix(facts): gather required facts if not already available
!56
2024-04-24 11:06:21 +09:30
Jon
6faee04b39 docs: add note about netbox fileds bug
!56
2024-04-23 23:19:59 +09:30
Jon
ef8255cca6 fix(install): correct template installed var
!56
2024-04-23 23:05:19 +09:30
Jon
725e8dbfec fix(install): as part of install check, confirm service
!56
2024-04-23 23:02:35 +09:30
Jon
c5b9420ed9 feat(services): add netbox service fields
!56
2024-04-23 23:01:40 +09:30
Jon
c5b4add4c7 feat(role): New role kubernetes_netbox
!56
2024-04-19 22:07:41 +09:30
Jon
aa3735f271 Merge branch '14-k3s-upgrades' into 'development'
test: fixing of deb 12

See merge request nofusscomputing/projects/ansible/collections/kubernetes!55
2024-03-29 20:03:03 +00:00
Jon
0ccb121955 ci(build): build job must occur on dev and master branch for test results
!55
2024-03-30 05:20:55 +09:30
Jon
98a9e6dcdf test(debian12): set PIP_BREAK_SYSTEM_PACKAGES=1
!55
2024-03-30 04:34:31 +09:30
Jon
7271e28c76 test(debian12): fix iptables missing rules.v6
!54
2024-03-30 04:32:42 +09:30
70a350bf56 build: bump version 1.5.0 -> 1.6.0
!54
2024-03-29 18:51:00 +00:00
Jon
af10814791 fix(docs): use correct badge query url
!54
2024-03-30 04:07:42 +09:30
Jon
f139827554 Merge branch '14-k3s-upgrades' into 'development'
feat: Support upgrading cluster

Closes #14

See merge request nofusscomputing/projects/ansible/collections/kubernetes!53
2024-03-29 18:02:51 +00:00
Jon
5980123e7a feat(test): add integration test. playbook install
!53
2024-03-30 03:20:36 +09:30
Jon
7ef739d063 feat: add retry=3 delay=10 secs to all ansible url modules
!53
2024-03-30 03:08:17 +09:30
Jon
4d44c01b32 refactor(galaxy): for dependent collections prefix with >= so as to not cause version lock
!53
2024-03-29 20:03:43 +09:30
Jon
c5371b8ff4 feat(upgrade): If upgrade occurs, dont run remaining tasks
!53
2024-03-29 19:44:38 +09:30
Jon
7c20146660 chore: fix yaml schema paths for vscode
!53
2024-03-29 19:18:42 +09:30
Jon
6c4616873e feat: support upgrading cluster
In place binary upgrades was chosen as its just a matter of changing binary and restarting the service

!53 closes #14
2024-03-29 19:18:28 +09:30
3243578951 build: bump version 1.4.0 -> 1.5.0
!52
2024-03-21 17:42:16 +00:00
Jon
0fd15f2195 feat(collection): nofusscomputing.firewall update 1.0.1 -> 1.1.0
!52
2024-03-22 03:08:51 +09:30
03e48c7031 build: bump version 1.3.0 -> 1.4.0
!50
2024-03-20 11:22:53 +00:00
Jon
11756037a3 Merge branch '22-check-mode' into 'development'
feat: check mode

Closes #22

See merge request nofusscomputing/projects/ansible/collections/kubernetes!50
2024-03-20 11:19:33 +00:00
Jon
6498a48e82 feat(install): "ansible_check_mode=true" no hostname check
!50 fixes #22
2024-03-20 20:46:46 +09:30
053d1f17ec build: bump version 1.2.0 -> 1.3.0
!48
2024-03-18 10:05:36 +00:00
Jon
17ff472577 Merge branch '2024-03-18' into 'development'
fix: couple of fixes

Closes #19 and #20

See merge request nofusscomputing/projects/ansible/collections/kubernetes!48
2024-03-18 10:00:49 +00:00
Jon
ec94414383 docs: add warning for not configuring firewall before install
!48 fixes #19
2024-03-18 19:18:02 +09:30
Jon
1faae0327e fix(handler): add missing 'reboot_host' handler
!48 fixes #20
2024-03-18 19:11:25 +09:30
Jon
17e3318c3c fix(firewall): ensure slave nodes can access ALL masters API point
!48
2024-03-18 19:09:17 +09:30
Jon
89b5593abf fix(firewall): dont add rules for disabled features
!48
2024-03-18 19:08:33 +09:30
Jon
10eae79a74 feat: dont attempt to install if already installed
!48
2024-03-18 19:07:55 +09:30
0be7080089 build: bump version 1.1.2 -> 1.2.0
!46
2024-03-16 13:58:16 +00:00
Jon
d3666c6825 Merge branch 'firewall' into 'development'
feat: migrate to firewall collection

Closes firewall#4

See merge request nofusscomputing/projects/ansible/collections/kubernetes!46
2024-03-16 13:54:29 +00:00
Jon
4af31ff3ac feat(firewall): use collection nofusscomputing.firewall to configure kubernetes firewall
!46
2024-03-16 23:05:01 +09:30
Jon
74187c7023 fix(config): use correct var name when setting node name
!46
2024-03-16 22:13:20 +09:30
47ac3095b6 Merge branch 'automated-tasks' into 'development'
chore(gitlab-ci): Automated update of git sub-module

See merge request nofusscomputing/projects/ansible/collections/kubernetes!45
2024-03-16 11:35:31 +00:00
dd4638bc93 chore(git): updated submodule gitlab-ci
Automation Data:
{
    "branch": "development",
    "current_commit": "9afa68d1f3849e491fa8ca034749388808531b74)",
    "name": "gitlab-ci",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/gitlab-ci",
    "remote_head": "a24f352ca3d82b8d0f02f5db20173fe2c3f71a4a)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/projects/gitlab-ci.git"
}

Changes: Submodule path gitlab-ci: checked out a24f352ca3d82b8d0f02f5db20173fe2c3f71a4a

MR !45
2024-03-16 11:34:50 +00:00
3ed6fd0f4c Merge branch 'automated-tasks' into 'development'
chore(gitlab-ci): Automated update of git sub-module

See merge request nofusscomputing/projects/ansible/collections/kubernetes!44
2024-03-14 12:46:56 +00:00
beb1bd2006 chore(git): updated submodule gitlab-ci
Automation Data:
{
    "branch": "development",
    "current_commit": "41eeb7badd582175b371cd4a5b2192decbcb0210)",
    "name": "gitlab-ci",
    "path": "/builds/nofusscomputing/projects/ansible/collections/kubernetes/_automation_/gitlab-ci",
    "remote_head": "9afa68d1f3849e491fa8ca034749388808531b74)",
    "remote_name": "origin",
    "url": "https://gitlab.com/nofusscomputing/projects/gitlab-ci.git"
}

Changes: Submodule path gitlab-ci: checked out 9afa68d1f3849e491fa8ca034749388808531b74

MR !44
2024-03-14 12:46:14 +00:00
4a83550530 build: bump version 1.1.1 -> 1.1.2
!42
2024-03-13 16:16:32 +00:00
Jon
7c54b19b64 Merge branch 'dont-rush-to-release-next-time-jon' into 'development'
fix: Dont rush to release next time jon

Closes #17 and #18

See merge request nofusscomputing/projects/ansible/collections/kubernetes!42
2024-03-13 16:13:02 +00:00
Jon
173c840121 fix(readme): update gitlab links to new loc
!42
2024-03-14 01:37:59 +09:30
Jon
f0f5d686fa chore: correct galaxy build ignores
!42
2024-03-14 01:36:31 +09:30
Jon
536c6e7b26 fix(configure): dont attempt to configure firewall if install=false
!42
2024-03-14 01:15:08 +09:30
Jon
a23bc5e9ee fix(handler): remove old k8s code causing handler to fail
!42
2024-03-14 01:00:20 +09:30
Jon
5444f583e5 fix(handler): kubernetes restart handler now using updated node type vars
!42
2024-03-14 00:55:09 +09:30
Jon
b4ad0a4e61 fix(config): if hostname=localhost use hostname command to fetch hostname
!42
2024-03-14 00:51:37 +09:30
Jon
c9961973e1 fix: limit the use of master group
!42
2024-03-14 00:39:22 +09:30
Jon
622338e497 fix: add missing dependency ansible.posix
!42 fixes #17
2024-03-14 00:32:59 +09:30
Jon
dec65ed57c fix(install): use correct var type for packages
!42 fixes #18
2024-03-14 00:31:26 +09:30
40 changed files with 1624 additions and 239 deletions

View File

@ -1 +0,0 @@
galaxy.yml galaxy[version-incorrect]

View File

@ -4,5 +4,5 @@ commitizen:
prerelease_offset: 1
tag_format: $version
update_changelog_on_bump: false
version: 1.1.1
version: 1.13.2
version_scheme: semver

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
artifacts/
build/
test_results/
test_results.json
*.tar.gz

View File

@ -9,6 +9,7 @@ variables:
include:
- local: .gitlab/integration_test.gitlab-ci.yml
- project: nofusscomputing/projects/gitlab-ci
ref: development
file:
@ -21,6 +22,40 @@ include:
- automation/.gitlab-ci-ansible.yaml
Build Collection:
extends: .ansible_collection_build
needs:
- job: Ansible Lint
optional: true
- job: Ansible Lint (galaxy.yml)
optional: true
rules:
- if: $CI_COMMIT_TAG
when: always
# Needs to run, even by bot as the test results need to be available
# - if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
# when: never
- if: # Occur on merge
$CI_COMMIT_BRANCH
&&
$CI_PIPELINE_SOURCE == "push"
when: always
# - if:
# $CI_COMMIT_BRANCH != "development"
# &&
# $CI_COMMIT_BRANCH != "master"
# &&
# $CI_PIPELINE_SOURCE == "push"
# when: always
- when: never
Update Git Submodules:
extends: .ansible_playbook_git_submodule

View File

@ -0,0 +1,219 @@
.integration_test:
stage: test
needs:
- "Build Collection"
image:
name: nofusscomputing/docker-buildx-qemu:dev
pull_policy: always
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
# GIT_STRATEGY: none
services:
- name: docker:23-dind
entrypoint: ["env", "-u", "DOCKER_HOST"]
command: ["dockerd-entrypoint.sh"]
before_script:
- | # start test container
docker run -d \
--privileged \
-v ${PWD}:/workdir \
-v ${PWD}/artifacts/galaxy:/collection \
--workdir /workdir \
--rm \
--env "ANSIBLE_FORCE_COLOR=true" \
--env "CI_COMMIT_SHA=${CI_COMMIT_SHA}" \
--env "ANSIBLE_LOG_PATH=/workdir/ansible.log" \
--env "PIP_BREAK_SYSTEM_PACKAGES=1" \
--name test_image_${CI_JOB_ID} \
nofusscomputing/ansible-docker-os:dev-${test_image}
- | # enter test container
docker exec -i test_image_${CI_JOB_ID} ps aux
- docker ps
- docker exec -i test_image_${CI_JOB_ID} bash -c 'apt update || true'
- docker exec -i test_image_${CI_JOB_ID} bash -c 'apt update || true'
- docker exec -i test_image_${CI_JOB_ID} apt update
- docker exec -i test_image_${CI_JOB_ID} apt install -y --no-install-recommends python3-pip net-tools dnsutils iptables
- |
if [ "${test_image}" == 'debian-12' ]; then
echo "Debian 12":
docker exec -i test_image_${CI_JOB_ID} pip install ansible-core --break-system-packages;
docker exec -i test_image_${CI_JOB_ID} mkdir -p /etc/iptables;
docker exec -i test_image_${CI_JOB_ID} touch /etc/iptables/rules.v6;
docker exec -i test_image_${CI_JOB_ID} update-alternatives --set iptables /usr/sbin/iptables-legacy;
else
echo " Not Debian 12":
docker exec -i test_image_${CI_JOB_ID} pip install ansible-core;
fi
- docker exec -i test_image_${CI_JOB_ID} cat /etc/hosts
- docker exec -i test_image_${CI_JOB_ID} cat /etc/resolv.conf
- | # check if DNS working
docker exec -i test_image_${CI_JOB_ID} nslookup google.com
script:
- | # inside container?
docker exec -i test_image_${CI_JOB_ID} ls -l /collection;
docker exec -i test_image_${CI_JOB_ID} echo $PWD;
- | # Show Network Interfaces
docker exec -i test_image_${CI_JOB_ID} ifconfig;
- | # Install the collection
docker exec -i test_image_${CI_JOB_ID} bash -c 'ansible-galaxy collection install $(ls /collection/*.tar.gz)'
- | # output ansible vars
docker exec -i test_image_${CI_JOB_ID} ansible -m setup localhost
- | # run the collection
docker exec -i test_image_${CI_JOB_ID} \
${test_command} \
--extra-vars "nfc_role_firewall_policy_input=ACCEPT" \
--extra-vars "nfc_role_firewall_policy_forward=ACCEPT" \
-vv
- | # Create test.yaml
mkdir -p test_results;
cat <<EOF > test_results/${test_image}.json
{
"$( echo ${test_image} | sed -e 's/\./_/')": "Pass"
}
EOF
after_script:
- | # Create test.yaml if not exists
if [ ! -f test_results/${test_image}.json ]; then
echo "[TRACE] Test has failed"
mkdir -p test_results;
cat <<EOF > test_results/${test_image}.json
{
"$( echo ${test_image} | sed -e 's/\./_/')": "Fail"
}
EOF
fi
- | # Run trace script for debugging
chmod +x ./.gitlab/integration_test_trace.sh;
./.gitlab/integration_test_trace.sh;
artifacts:
untracked: false
paths:
- ansible.log
- test_results/*
when: always
rules:
- if: $CI_COMMIT_TAG
allow_failure: true
when: on_success
# Needs to run, even by bot as the test results need to be available
# - if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
# when: never
- if: # Occur on merge
$CI_COMMIT_BRANCH
&&
$CI_PIPELINE_SOURCE == "push"
allow_failure: true
when: on_success
# - if:
# $CI_COMMIT_BRANCH != "development"
# &&
# $CI_COMMIT_BRANCH != "master"
# &&
# $CI_PIPELINE_SOURCE == "push"
# allow_failure: true
# when: always
- when: never
Playbook - Install:
extends: .integration_test
parallel:
matrix:
- test_image: debian-11
test_command: ansible-playbook nofusscomputing.kubernetes.install
- test_image: debian-12
test_command: ansible-playbook nofusscomputing.kubernetes.install
- test_image: ubuntu-20.04
test_command: ansible-playbook nofusscomputing.kubernetes.install
- test_image: ubuntu-22.04
test_command: ansible-playbook nofusscomputing.kubernetes.install
test_results:
stage: test
extends: .ansible_playbook
variables:
ansible_playbook: .gitlab/test_results.yaml
ANSIBLE_PLAYBOOK_DIR: $CI_PROJECT_DIR
needs:
- Playbook - Install
artifacts:
untracked: false
when: always
access: all
expire_in: "3 days"
paths:
- test_results.json
rules:
- if: $CI_COMMIT_TAG
allow_failure: true
when: on_success
# Needs to run, even by bot as the test results need to be available
# - if: "$CI_COMMIT_AUTHOR =='nfc_bot <helpdesk@nofusscomputing.com>'"
# when: never
- if: # Occur on merge
$CI_COMMIT_BRANCH
&&
$CI_PIPELINE_SOURCE == "push"
allow_failure: true
when: on_success
# - if:
# $CI_COMMIT_BRANCH != "development"
# &&
# $CI_COMMIT_BRANCH != "master"
# &&
# $CI_PIPELINE_SOURCE == "push"
# allow_failure: true
# when: always
- when: never

View File

@ -0,0 +1,42 @@
#!/bin/bash
# colour ref: https://stackoverflow.com/a/28938235
NC='\033[0m' # Text Reset
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
cmd() {
echo -e "${Yellow}[TRACE] ${Green}executing ${Cyan}'$1'${NC}"
docker exec -i test_image_${CI_JOB_ID} $1 || true
}
cmd "journalctl -xeu netfilter-persistent.service";
cmd "journalctl -xeu iptables.service"
cmd "journalctl -xeu k3s.service"
cmd "systemctl status netfilter-persistent.service"
cmd "systemctl status iptables.service"
cmd "systemctl status k3s.service"
cmd "kubectl get po -A -o wide"
cmd "kubectl get no -o wide"
cmd "iptables -nvL --line-numbers"

View File

View File

@ -0,0 +1,22 @@
### :books: Summary
<!-- your summary here emojis ref: https://github.com/yodamad/gitlab-emoji -->
### :link: Links / References
<!-- using a list as any links to other references or links as required. if relevent, describe the link/reference -->
### :construction_worker: Tasks
- [ ] Add your tasks here if required (delete)
<!-- dont remove tasks below strike through including the checkbox by enclosing in double tidle '~~' -->
- [ ] Playbook Update
This collection has a [corresponding playbook](https://gitlab.com/nofusscomputing/projects/ansible/ansible_playbooks/-/blob/development/role.yaml) that may need to be updated (Ansible Role), specifically [Role Validation](https://gitlab.com/nofusscomputing/projects/ansible/ansible_playbooks/-/blob/development/tasks/role/validation/nfc_kubernetes.yaml).
- [ ] NetBox Rendered Config Update
This Collection has a [NetBox Rendered Config template](https://gitlab.com/nofusscomputing/infrastructure/configuration-management/netbox/-/blob/development/templates/cluster.json.j2) that may need to be updated. Specifically Section `cluster.type == 'kubernetes'`

19
.gitlab/test_results.yaml Normal file
View File

@ -0,0 +1,19 @@
---
- name: Create Test Results File
hosts: localhost
gather_facts: false
tasks:
- name: Load Test Results
ansible.builtin.include_vars:
dir: ../test_results
name: test_results
- name: Create Results file
ansible.builtin.copy:
content: "{{ (test_results) | to_nice_json }}"
dest: ../test_results.json

15
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"yaml.schemas": {
"https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/tasks": [
"roles/nfc_kubernetes/tasks/*.yaml",
"roles/nfc_kubernetes/tasks/*/*.yaml",
"roles/nfc_kubernetes/tasks/*/*/*.yaml"
],
"https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/vars.json": [
"roles/nfc_kubernetes/variables/**.yaml"
],
"https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/playbook": ".gitlab/test_results.yaml"
},
"gitlab.aiAssistedCodeSuggestions.enabled": false,
"gitlab.duoChat.enabled": false,
}

View File

@ -1,54 +1,71 @@
## 1.1.1 (2024-03-13)
## 1.13.2 (2024-07-30)
### Fix
- don't check hostname for localhost
- **nfc_kubernetes**: correct logic for prime node to always be labeled prime
## 1.1.0 (2024-03-13)
### Feat
- add role readme and fix gitlab release job
## 1.0.1 (2024-03-13)
## 1.13.1 (2024-07-28)
### Fix
- **ci**: ensure correct package name is used
- **nfc_kubernetes**: prime node to always be labeled prime
## 1.0.0 (2024-03-13)
### BREAKING CHANGE
- Repository restructure from Ansible Role to Ansible Collection
## 1.13.0 (2024-07-28)
### Feat
- **playbook**: add the install playbook
- restructure repository as ansible collection
- **nfc_kubernetes**: prime node to always be labeled prime
- **nfc_kubernetes**: ability to add node labels and taints
### Refactor
- **nfc_kubernetes**: update meta file
- remove dependency on role nfc_common
- **nfc_kubernetes**: layout role ingress to install prime -> master -> worker nodes as separate groups
- **docs**: restructure docs
## 0.3.0 (2024-03-13)
### Feat
- remove old var and update kube version
- install helm binary
- disable node ipv6 support
- **kubevirt**: install virtctl plugin
- **kubevirt**: optionally specify which nodes within a cluster to install kubeviirt
- **kubevirt**: Default to live migration for update strategy
## 1.12.0 (2024-07-08)
### Fix
- remove depreciated worker var
- **kubernetes_roles**: conditional checks for prime
- **kubernetes_roles**: conditional checks for prime
- **kubernetes_roles**: conditional checks for prime
- **kubernetes_roles**: clean up white space
- **kubernetes_roles**: clean up white space
- **kubernetes_roles**: clean up white space
- **kubernetes_roles**: clean up white space
- **kubernetes_role**: delete leftover ]
- **kubernetes_role**: Change "https://" + hostvars[ns.prime_name].ansible_host + ":6443" -> "https://" + ns.prime_name.ansible_host + ":6443"
- **kubernetes_role**: get prime hostname
- **kubernetes_role**: set server var -> "https://" + hostvars[nfc_role_kubernetes_node_prime].ansible_host + ":6443"
- **kubernetes_role**: remove not nfc_role_kubernetes_cluster_upgraded | default(true) | bool section
### Refactor
## 1.11.0 (2024-06-27)
- image var update for calico
### Feat
- **firewall**: update collection nfc_firewall 1.1.0 -> 1.1.1
## 1.10.3 (2024-06-27)
### Fix
- **install**: ensure ipv6 is installed before attempting to disable
## 1.10.2 (2024-05-03)
### Fix
- **nfc_kubernetes**: set default for var so task 'Copy Template' when clause doesn't fail task with undefined var
## 1.10.1 (2024-05-03)
### Fix
- **nfc_kubernetes**: set default for var so when clause doesn't fail task with undefined var
## 1.10.0 (2024-05-03)
### Fix
- **nfc_kubernetes**: correct 'Create Required directories' when logic
## 1.9.0 (2024-05-03)
### Feat
- **nfc_kubernetes**: add debug out to k3s download on failure

View File

@ -14,26 +14,31 @@
<br>
![Gitlab forks count](https://img.shields.io/badge/dynamic/json?label=Forks&query=%24.forks_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) ![Gitlab stars](https://img.shields.io/badge/dynamic/json?label=Stars&query=%24.star_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) [![Open Issues](https://img.shields.io/badge/dynamic/json?color=ff782e&logo=gitlab&style=plastic&label=Open%20Issues&query=%24.statistics.counts.opened&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fissues_statistics)](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes/-/issues)
![Gitlab forks count](https://img.shields.io/badge/dynamic/json?label=Forks&query=%24.forks_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) ![Gitlab stars](https://img.shields.io/badge/dynamic/json?label=Stars&query=%24.star_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) [![Open Issues](https://img.shields.io/badge/dynamic/json?color=ff782e&logo=gitlab&style=plastic&label=Open%20Issues&query=%24.statistics.counts.opened&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fissues_statistics)](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/issues)
![GitHub forks](https://img.shields.io/github/forks/NofussComputing/ansible_collection_kubernetes?logo=github&style=plastic&color=000000&labell=Forks) ![GitHub stars](https://img.shields.io/github/stars/NofussComputing/ansible_collection_kubernetes?color=000000&logo=github&style=plastic) ![Github Watchers](https://img.shields.io/github/watchers/NofussComputing/ansible_collection_kubernetes?color=000000&label=Watchers&logo=github&style=plastic)
<br>
This project is hosted on [gitlab](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes) and has a read-only copy hosted on [Github](https://github.com/NofussComputing/ansible_collection_kubernetes).
This project is hosted on [gitlab](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes) and has a read-only copy hosted on [Github](https://github.com/NofussComputing/ansible_collection_kubernetes).
----
**Stable Branch**
![Gitlab build status - stable](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Dmaster&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/kubernetes%2F-%2Fraw%2Fmaster%2F.cz.yaml)
![Gitlab build status - stable](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Dmaster&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes%2F-%2Fraw%2Fmaster%2F.cz.yaml)
![Debian 11](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'debian-11'%5D&style=plastic&logo=debian&logoColor=a80030&label=Debian%2011&color=a80030) ![Debian 12](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'debian-12'%5D&style=plastic&logo=debian&logoColor=a80030&label=Debian%2012&color=a80030) ![Ubuntu 20.04](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'ubuntu-20_04'%5D&style=plastic&logo=ubuntu&logoColor=dd4814&label=Ubuntu%2020&color=dd4814) ![Ubuntu 22.04](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'ubuntu-22_04'%5D&style=plastic&logo=ubuntu&logoColor=dd4814&label=Ubuntu%2022&color=dd4814)
----
**Development Branch**
![Gitlab build status - development](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Ddevelopment&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/kubernetes%2F-%2Fraw%2Fdevelopment%2F.cz.yaml)
![Gitlab build status - development](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Ddevelopment&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes%2F-%2Fraw%2Fdevelopment%2F.cz.yaml)
![Debian 11](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fdevelopment%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'debian-11'%5D&style=plastic&logo=debian&logoColor=a80030&label=Debian%2011&color=a80030) ![Debian 12](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fdevelopment%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'debian-12'%5D&style=plastic&logo=debian&logoColor=a80030&label=Debian%2012&color=a80030) ![Ubuntu 20.04](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fdevelopment%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'ubuntu-20_04'%5D&style=plastic&logo=ubuntu&logoColor=dd4814&label=Ubuntu%2020&color=dd4814) ![Ubuntu 22.04](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fdevelopment%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'ubuntu-22_04'%5D&style=plastic&logo=ubuntu&logoColor=dd4814&label=Ubuntu%2022&color=dd4814)
----
<br>
@ -42,14 +47,14 @@ This project is hosted on [gitlab](https://gitlab.com/nofusscomputing/projects/a
links:
- [Issues](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes/-/issues)
- [Issues](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/issues)
- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes/-/merge_requests)
- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/merge_requests)
## Contributing
All contributions for this project must conducted from [Gitlab](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes).
All contributions for this project must conducted from [Gitlab](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes).
For further details on contributing please refer to the [contribution guide](CONTRIBUTING.md).

View File

@ -0,0 +1 @@
linked to

View File

@ -13,13 +13,15 @@ about: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernete
![Gitlab build status - stable](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Dmaster&logo=gitlab&style=plastic) ![Gitlab build status - development](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Ddevelopment&logo=gitlab&style=plastic)
![Debian 11](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'debian-11'%5D&style=plastic&logo=debian&logoColor=a80030&label=Debian%2011&color=a80030) ![Debian 12](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'debian-12'%5D&style=plastic&logo=debian&logoColor=a80030&label=Debian%2012&color=a80030) ![Ubuntu 20.04](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'ubuntu-20_04'%5D&style=plastic&logo=ubuntu&logoColor=dd4814&label=Ubuntu%2020&color=dd4814) ![Ubuntu 22.04](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fjobs%2Fartifacts%2Fmaster%2Fraw%2Ftest_results.json%3Fjob%3Dtest_results&query=%24%5B'ubuntu-22_04'%5D&style=plastic&logo=ubuntu&logoColor=dd4814&label=Ubuntu%2022&color=dd4814)
[![Downloads](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgalaxy.ansible.com%2Fapi%2Fv3%2Fplugin%2Fansible%2Fcontent%2Fpublished%2Fcollections%2Findex%2Fnofusscomputing%2Fkubernetes%2F&query=%24.download_count&style=plastic&logo=ansible&logoColor=white&label=Galaxy%20Downloads&labelColor=black&color=cyan)](https://galaxy.ansible.com/ui/repo/published/nofusscomputing/kubernetes/)
</span>
This Ansible Collection is for installing a K3s Kubernetes cluster, both single and multi-node cluster deployments are supported.
This Ansible Collection is for installing a K3s Kubernetes cluster, both single and multi-node cluster deployments are supported. In addition to installing and configuring the firewall for the node. for further information on the firewall config please see the [firewall docs](../firewall/index.md)
## Installation
@ -29,14 +31,20 @@ To install this collection use `ansible-galaxy collection install nofusscomputin
## Features
Most of the features of this collection are from the included role `nfc_kubernetes`, please [view its page for feature details](roles/nfc_kubernetes/index.md).
- Install k3s cluster. Both Single and multi-node clusters
- Configure the cluster
- Upgrade a cluster
For a more detailed list of featured checkout the roles [documentation](roles/nfc_kubernetes/index.md).
## Using this collection
This collection has been designed to be a complete and self-contained management tool for a K3s kubernetes cluster.
## K3s Kubernetes Installation
## Cluster Installation
By default the install playbook will install to localhost.
@ -46,6 +54,11 @@ ansible-playbook nofusscomputing.kubernetes.install
```
!!! danger
By default when the install task is run, The firewall is also configured. The default sets the `FORWARD` and `INPUT` tables to have a policy of `DROP`. Failing to add any required additional rules before installing/configuring kubernetes will cause you to not have remote access to the machine.
You are encouraged to run `ansible-playbook nofusscomputing.firewall.install` with your rules configured within your inventory first. see the [firewall docs](../firewall/index.md) for more information.
The install playbook has a dynamic `hosts` key. This has been done to specifically support running the playbook from AWX and being able to populate the field from the survey feature. Order of precedence for the host variable is as follows:
- `nfc_pb_host` set to any valid value that a playbook `hosts` key can accept
@ -59,4 +72,12 @@ The install playbook has a dynamic `hosts` key. This has been done to specifical
For the available variables please view the [nfc_kubernetes role docs](roles/nfc_kubernetes/index.md#default-variables)
## Cluster Upgrade
[In place cluster upgrades](https://docs.k3s.io/upgrades/manual#upgrade-k3s-using-the-binary) is the method used to conduct the cluster upgrades. The logic for the upgrades first confirms that K3s is installed and that the local binary and running k3s version are the desired versions. If they are not, they will be updated to the desired version. On completion of this the node has its `k3s` service restarted which completes the upgrade process.
!!! info
If an upgrade occurs, no other task within the play will run. This is by design. if you have further tasks to be run in addition to the upgrade, run the play again.
!!! danger
not following the [Kubernetes version skew policy](https://kubernetes.io/releases/version-skew-policy/) when upgrading your cluster may break your cluster.

View File

@ -0,0 +1,46 @@
---
title: NetBox Kubernetes
description: No Fuss Computings Ansible role kubernetes_netbox
date: 2023-10-24
template: project.html
about: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes
---
This Ansible role as part of our collection `nofusscomputing.kubernetes` is intended to be used to setup NetBox so that the settings for deploying a kubernetes cluster can be stored within NetBox.
## Role Details
| Item| Value | Description |
|:---|:---:|:---|
| Dependent Roles | _None_ | |
| Optional Roles | _None_ | |
| Idempotent | _Yes_ | |
| Stats Available | _Not Yet_ | |
| Tags | _Nil_ | |
| Requirements | _None_ | |
## Features
- Adds custom fields to `cluster` object within NetBox that this collection can use to deploy a kubernetes cluster.
!!! info
Due to a bug in ansible module `netbox.netbox.netbox_custom_field` The fields are not created as they should be. For example, the fields are supposed to be set to only display when not empty. for more information see [Github #1210](https://github.com/netbox-community/ansible_modules/issues/1210). We have [added a workaround](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/merge_requests/56#note_1876912267) so the fields are created.
Other than that, the fields are created as they should.
## Usage
To configure NetBox, ensure that the NetBox Access variables are set and run playbook `nofusscomputing.netbox.kubernetes_netbox`. This will setup NetBox with the required fields that role [nfc_kubernetes](../nfc_kubernetes/index.md) uses.
## Default Variables
``` yaml title="defaults/main.yaml" linenums="1"
--8<-- "roles/kubernetes_netbox/defaults/main.yaml"
```

View File

@ -10,7 +10,7 @@ This role include logic to generate firewall rules for iptables. Both IPv4 and I
Rules generation workflow:
- itertes over all kubernetes hosts
- iterates over all kubernetes hosts
- adds rules if host is masters for worker access

View File

@ -70,6 +70,8 @@ This Ansible role is designed to deploy a K3s Kubernetes cluster. Without adding
- Install the Helm Binary
- Upgrade cluster
## Role Workflow

View File

@ -8,7 +8,7 @@ namespace: nofusscomputing
name: kubernetes
# The version of the collection. Must be compatible with semantic versioning
version: 1.1.1
version: 1.13.2
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
@ -44,7 +44,10 @@ tags:
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
# range specifiers can be set and are separated by ','
dependencies:
kubernetes.core: '3.0.0'
ansible.posix: '>=1.5.4'
kubernetes.core: '>=3.0.0'
nofusscomputing.firewall: '>=1.1.1'
netbox.netbox: '>=3.16.0'
# The URL of the originating SCM repository
@ -64,17 +67,17 @@ issues: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernet
# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry',
# and '.git' are always filtered. Mutually exclusive with 'manifest'
build_ignore:
- .vscode/
- artifacts/
- docs/
- .gitlab*
- includes/
- website-template/
- .vscode
- artifacts
- docs
- .git*
- gitlab-ci
- website-template
- .ansible-lint-ignore
- .cz.yaml
- .nfc_automation.yaml
- dockerfile
- mkdocs.yaml
- mkdocs.yml
# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a
# list of MANIFEST.in style

View File

@ -49,6 +49,9 @@ nav:
- projects/ansible/collection/kubernetes/roles/nfc_kubernetes/release_notes.md
- Role kubernetes_netbox:
- projects/ansible/collection/kubernetes/roles/kubernetes_netbox/index.md
- Operations:

64
playbooks/netbox.yaml Normal file
View File

@ -0,0 +1,64 @@
---
- name: Install K3s Kubernetes
hosts: |-
{%- if nfc_pb_host is defined -%}
{{ nfc_pb_host }}
{%- elif nfc_pb_kubernetes_cluster_name is defined -%}
kubernetes_cluster_{{ nfc_pb_kubernetes_cluster_name | lower }}
{%- else -%}
{%- if ansible_limit is defined -%}
{{ ansible_limit }}
{%- else -%}
localhost
{%- endif -%}
{%- endif %}
become: false
gather_facts: false
tasks:
- name: Configure NetBox for Kubernetes Deployment(s)
ansible.builtin.include_role:
name: kubernetes_netbox
tags:
- always
# vars:
#
# Future feature, add playbook to import to awx
#
# nfc_pb_awx_tower_template:
# - name: "Collection/NoFussComputing/Kubernetes/NetBox/Configure"
# ask_credential_on_launch: true
# ask_job_type_on_launch: true
# ask_limit_on_launch: true
# ask_tags_on_launch: true
# ask_variables_on_launch: true
# description: |
# Playbook to Install/Configure Kubernetes using configuration
# from code.
# execution_environment: "No Fuss Computing EE"
# job_type: "check"
# labels:
# - cluster
# - k3s
# - kubernetes
# verbosity: 2
# use_fact_cache: true
# survey_enabled: false

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pynetbox
pytz

9
roles/defaults/main.yaml Normal file
View File

@ -0,0 +1,9 @@
---
#
# NetBox Access Variables. Required
#
# nfc_pb_api_netbox_url: # ENV [NETBOX_API]
# nfc_pb_api_netbox_token: # ENV [NETBOX_TOKEN]
# nfc_pb_api_netbox_validate_cert: true # ENV [NETBOX_VALIDATE_CERT]

View File

@ -0,0 +1,3 @@
## No Fuss Computing - Ansible Role kubernetes_netbox
Nothing to see here

View File

@ -0,0 +1,30 @@
galaxy_info:
role_name: kubernetes_netbox
author: No Fuss Computing
description: Configure the required items within Netbox to support deploying kubernetes from Netbox configuration.
issue_tracker_url: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes
license: MIT
min_ansible_version: '2.15'
platforms:
- name: Debian
versions:
- bullseye
- bookworm
- name: Ubuntu
versions:
- 21
galaxy_tags:
- cluster
- k3s
- kubernetes
- netbox

View File

@ -0,0 +1,255 @@
---
# add cluster type kubernetes
- name: Create Custom Field - Configure Firewall
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Configure Firewall
name: nfc_role_kubernetes_configure_firewall
type: boolean
ui_visibility: 'hidden-ifunset'
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - ETCD Enabled
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: ETCD Enabled
name: nfc_role_kubernetes_etcd_enabled
type: boolean
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Install OLM
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Install OLM
name: nfc_role_kubernetes_install_olm
type: boolean
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Install Helm
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Install Helm
name: nfc_role_kubernetes_install_helm
type: boolean
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Install KubeVirt
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Install KubeVirt
name: nfc_role_kubernetes_install_kubevirt
type: boolean
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - KubeVirt Operator Replicas
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: KubeVirt Operator Replicas
name: nfc_role_kubernetes_kubevirt_operator_replicas
type: integer
ui_visibility: hidden-ifunset
# is_cloneable: false
validation_minimum: 1
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Enable MetalLB
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Enable MetalLB
name: nfc_kubernetes_enable_metallb
type: boolean
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Enable ServiceLB (klipper)
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Enable ServiceLB (klipper)
name: nfc_kubernetes_enable_servicelb
type: boolean
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Pod Subnet
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Pod Subnet
name: nfc_role_kubernetes_pod_subnet
object_type: ipam.prefix
type: object
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Service Subnet
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- virtualization.cluster
default: null
group_name: Kubernetes
label: Service Subnet
name: nfc_role_kubernetes_service_subnet
object_type: ipam.prefix
type: object
ui_visibility: hidden-ifunset
# is_cloneable: false
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp

View File

@ -0,0 +1,21 @@
---
- name: Setup NetBox for Kubernetes Cluster Deployments
ansible.builtin.include_tasks:
file: cluster.yaml
apply:
tags:
- always
tags:
- always
- name: Setup NetBox for Kubernetes Service Deployments
ansible.builtin.include_tasks:
file: services.yaml
apply:
tags:
- always
tags:
- never
- services

View File

@ -0,0 +1,50 @@
---
- name: Create Custom Field - Instance
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- ipam.service
group_name: Kubernetes
label: Instance Name
description: "Name of the Instance to be deployed"
name: service_kubernetes_instance
type: text
ui_visibility: hidden-ifunset
# is_cloneable: true
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp
- name: Create Custom Field - Namespace
netbox.netbox.netbox_custom_field:
netbox_url: "{{ lookup('env', 'NETBOX_API') | default(nfc_pb_api_netbox_url) }}"
netbox_token: "{{ lookup('env', 'NETBOX_TOKEN') | default(nfc_pb_api_netbox_token) }}"
data:
content_types:
- ipam.service
group_name: Kubernetes
label: Service Namespace
description: "Deployment Namespace"
name: service_kubernetes_namespace
type: text
ui_visibility: hidden-ifunset
# is_cloneable: true
weight: 100
state: present
validate_certs: "{{ lookup('env', 'NETBOX_VALIDATE_CERT') | default(nfc_pb_api_netbox_validate_cert) | default(true) | bool }}"
delegate_to: localhost
failed_when: >
custom_field_tmp.msg != 'ui_visibility does not exist on existing object. Check to make sure valid field.'
and
custom_field_tmp.diff is not defined
register: custom_field_tmp

View File

@ -34,6 +34,8 @@ nfc_role_kubernetes_container_images:
nfc_role_kubernetes_cluster_domain: cluster.local
nfc_role_kubernetes_configure_firewall: true
nfc_role_kubernetes_etcd_enabled: false
nfc_role_kubernetes_install_olm: false
@ -44,13 +46,19 @@ nfc_role_kubernetes_install_kubevirt: false
nfc_role_kubernetes_kubevirt_operator_replicas: 1
nfc_role_kubernetes_node_labels: {} # Optional, Dict. Node labels.
nfc_role_kubernetes_node_taints: {} # Optional, Dict. Node taints.
# nfc_role_kubernetes_node_prime: '' # Mandatory*, string. the inventory_hostname of the prime node. ONLY required for multi-node deployments
nfc_role_kubernetes_oidc_enabled: false
nfc_role_kubernetes_resolv_conf_file: /etc/resolv.conf
nfc_role_kubernetes_pod_subnet: 172.16.248.0/21
nfc_role_kubernetes_service_subnet: 172.16.244.0/22
nfc_role_kubernetes_prime: true # Mandatory for a node designated as the prime master node
nfc_role_kubernetes_master: true # Mandatory for a node designated as a master node and the prime master node
nfc_role_kubernetes_prime: false # Mandatory for a node designated as the prime master node
nfc_role_kubernetes_master: false # Mandatory for a node designated as a master node and the prime master node
nfc_role_kubernetes_worker: false # Mandatory for a node designated as a worker node
############################################################################################################
@ -132,7 +140,7 @@ k3s:
# usernames: []
# runtimeClasses: []
# namespaces: [kube-system]
when: "{{ kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname }}"
when: "{{ nfc_role_kubernetes_prime | bool }}"
#############################################################################################

View File

@ -1,31 +1,20 @@
---
- name: "restart ContainerD"
service:
name: containerd
state: restarted
when: >
containerd_config.changed | default(false) | bool
and
containerd_installed.rc | default(1) | int == 0
and
kubernetes_type == 'k8s'
tags:
- configure
- install
- name: Reboot Node
ansible.builtin.reboot:
reboot_timeout: 300
listen: reboot_host
when: ansible_connection == 'ssh'
- name: Restart Kubernetes
ansible.builtin.service:
name: |-
{%- if kubernetes_type == 'k3s' -%}
{%- if Kubernetes_Master | default(false) | bool -%}
k3s
{%- else -%}
k3s-agent
{%- endif -%}
{%- if nfc_role_kubernetes_master | default(false) | bool -%}
k3s
{%- else -%}
kubelet
{%- endif %}
k3s-agent
{%- endif -%}
state: restarted
listen: kubernetes_restart
when: |-
@ -33,21 +22,20 @@
nfc_kubernetes_no_restart
or
(
inventory_hostname in groups['kubernetes_master']
nfc_role_kubernetes_master
and
nfc_kubernetes_no_restart_master
)
or
(
inventory_hostname == kubernetes_config.cluster.prime.name
inventory_hostname == kubernetes_config.cluster.prime.name | default(inventory_hostname)
and
nfc_kubernetes_no_restart_prime
)
or
(
inventory_hostname in groups['kubernetes_worker']
nfc_role_kubernetes_worker
and
nfc_kubernetes_no_restart_slave
)
)

View File

@ -5,6 +5,9 @@
url: https://baltocdn.com/helm/signing.asc
dest: /usr/share/keyrings/helm.asc
mode: 740
changed_when: not ansible_check_mode
delay: 10
retries: 3
- name: Add Helm Repository

View File

@ -4,7 +4,10 @@
ansible.builtin.command:
cmd: hostname
changed_when: false
check_mode: false
register: hostname_to_check
tags:
- always
- name: Hostname Check
@ -12,37 +15,72 @@
that:
- hostname_to_check.stdout == inventory_hostname
msg: The hostname must match the inventory_hostname
tags:
- always
when: >
inventory_hostname != 'localhost'
- name: Testing Env Variables
ansible.builtin.set_fact:
ansible_default_ipv4: {
"address": "127.0.0.1"
}
check_mode: false
tags:
- always
when: >
lookup('ansible.builtin.env', 'CI_COMMIT_SHA') | default('') != ''
- name: Gather Facts required by role
ansible.builtin.setup:
gather_subset:
- all_ipv4_addresses
- os_family
- processor
tags:
- always
when: >
ansible_architecture is not defined
or
ansible_default_ipv4 is not defined
or
ansible_os_family is not defined
- name: Check Machine Architecture
ansible.builtin.set_fact:
nfc_kubernetes_install_architectures: "{{ nfc_kubernetes_install_architectures | default({}) | combine({ansible_architecture: ''}) }}"
tags:
- always
- name: Firewall Rules
- name: Configure Kubernetes Firewall Rules
ansible.builtin.include_role:
name: nfc_firewall
name: nofusscomputing.firewall.nfc_firewall
vars:
nfc_firewall_enabled_kubernetes: "{{ nfc_kubernetes.enable_firewall | default(false) | bool }}"
nfc_role_firewall_firewall_type: iptables
nfc_role_firewall_additional_rules: "{{ ( lookup('template', 'vars/firewall_rules.yaml') | from_yaml ).kubernetes_chains }}"
tags:
- never
- install
- always
when: >
nfc_role_kubernetes_configure_firewall
# fix, reload firewall `iptables-reloader`
- name: Reload iptables
ansible.builtin.command:
cmd: bash -c /usr/bin/iptables-reloader
changed_when: false
- name: Install required software
ansible.builtin.apt:
name: python3-pip
install_recommends: false
state: present
when: >
install_kubernetes | default(true) | bool
and
not kubernetes_installed | default(false) | bool
tags:
- never
- install
- always
# kubernetes_installed
- name: K3s Install
ansible.builtin.include_tasks:
file: k3s/install.yaml
@ -67,6 +105,8 @@
install_kubernetes | default(true) | bool
and
kubernetes_installed | default(false) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
tags:
- always
@ -83,6 +123,8 @@
kubernetes_config.kube_virt.enabled | default(nfc_role_kubernetes_install_kubevirt)
and
inventory_hostname in kubernetes_config.kube_virt.nodes | default([ inventory_hostname ]) | list
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
tags:
- always
@ -99,5 +141,7 @@
kubernetes_config.helm.enabled | default(nfc_role_kubernetes_install_helm)
and
nfc_role_kubernetes_master
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
tags:
- always

View File

@ -14,7 +14,7 @@
- name: Check if FW dir exists
ansible.builtin.stat:
name: /etc/iptables.rules.d
name: /etc/iptables-reloader/rules.d
register: firewall_rules_dir_metadata
@ -34,12 +34,21 @@
- src: kubernetes-manifest-rbac.yaml.j2
dest: /var/lib/rancher/k3s/server/manifests/rbac-authorization-common.yaml
when: "{{ kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname }}"
when: "{{ nfc_role_kubernetes_prime | bool }}"
- src: iptables-kubernetes.rules.j2
dest: "/etc/iptables.rules.d/iptables-kubernetes.rules"
dest: "/etc/iptables-reloader/rules.d/iptables-kubernetes.rules"
notify: firewall_reloader
when: "{{ firewall_rules_dir_metadata.stat.exists }}"
when: |-
{%- if firewall_installed | default(false) -%}
{{ firewall_rules_dir_metadata.stat.exists }}
{%- else -%}
false
{%- endif %}
- name: Add Kubernetes Node Labels
@ -49,21 +58,41 @@
kind: Node
metadata:
name: "{{ inventory_hostname }}"
{% if kubernetes_config.hosts[inventory_hostname].labels | default([]) | list | length > 0 -%}
{% if
nfc_role_kubernetes_node_labels
and
not nfc_role_kubernetes_prime | bool
-%}
labels:
{{ kubernetes_config.hosts[inventory_hostname].labels | to_nice_yaml | indent(4) }}
{{ nfc_role_kubernetes_node_labels | to_nice_yaml(indent=0) | indent(4) }}
{% elif
nfc_role_kubernetes_prime | bool
%}
labels:
node-role.kubernetes.io/prime: "true"
{% if nfc_role_kubernetes_node_labels %}
{{ nfc_role_kubernetes_node_labels | to_nice_yaml(indent=0) | indent(4) }}
{% endif %}
{%- endif +%}
{% if kubernetes_config.hosts[inventory_hostname].taints | default([]) | list | length > 0 -%}
{% if nfc_role_kubernetes_node_taints -%}
spec:
taints:
{{ kubernetes_config.hosts[inventory_hostname].taints | to_nice_yaml(indent=0) | indent(4) }}
{{ nfc_role_kubernetes_node_taints | to_nice_yaml(indent=0) | indent(4) }}
{% endif %}
dest: /var/lib/rancher/k3s/server/manifests/node-manifest-{{ inventory_hostname }}.yaml
owner: root
group: root
mode: '700'
delegate_to: "{{ kubernetes_config.cluster.prime.name }}"
delegate_to: "{{ nfc_role_kubernetes_node_prime }}"
when:
kubernetes_config.hosts[inventory_hostname].labels | default([]) | list | length > 0
nfc_role_kubernetes_node_labels
or
kubernetes_config.hosts[inventory_hostname].taints | default([]) | list | length > 0
nfc_role_kubernetes_node_taints
or
nfc_role_kubernetes_prime | bool

View File

@ -1,15 +1,30 @@
---
- name: Install required python modules
ansible.builtin.pip:
name: "{{ item }}"
state: present
loop: "{{ pip_packages }}"
vars:
pip_packages:
- kubernetes>=12.0.0
- PyYAML>=3.11
- name: Check for calico deployment manifest
ansible.builtin.stat:
name: /var/lib/rancher/k3s/server/manifests/calico.yaml
register: file_calico_yaml_metadata
when: >
nfc_role_kubernetes_prime | bool
- name: Check for calico Operator deployment manifest
ansible.builtin.stat:
name: /var/lib/rancher/k3s/ansible/deployment-manifest-calico_operator.yaml
register: file_calico_operator_yaml_metadata
when: >
nfc_role_kubernetes_prime | bool
- name: Install dependent packages
@ -21,10 +36,11 @@
loop_var: package
vars:
packages:
- name: curl
- name: iptables
- name: jq
- name: wireguard
- wget
- curl
- iptables
- jq
- wireguard
- name: Remove swapfile from /etc/fstab
@ -41,14 +57,29 @@
- install
- name: Disable swap
ansible.builtin.command:
cmd: swapoff -a
changed_when: false
when:
- ansible_os_family == 'Debian'
tags:
- install
- name: Testing Environment try/catch
block:
- name: Disable swap
ansible.builtin.command:
cmd: swapoff -a
changed_when: false
when:
- ansible_os_family == 'Debian'
tags:
- install
rescue:
- name: Check if inside Gitlab CI
ansible.builtin.assert:
that:
- lookup('ansible.builtin.env', 'CI_COMMIT_SHA') | default('') != ''
success_msg: "Inside testing enviroment, 'Disable swap' error OK"
fail_msg: "You should figure out what went wrong"
- name: Check an armbian os system
ansible.builtin.stat:
@ -81,15 +112,30 @@
- name: /var/lib/rancher/k3s/server/logs
state: directory
mode: 700
when: >
{{ nfc_role_kubernetes_master | bool }}
- name: /var/lib/rancher/k3s/server/manifests
state: directory
mode: 700
when: >
{{ nfc_role_kubernetes_master | bool }}
- name: /var/lib/rancher/k3s/ansible
state: directory
mode: 700
when: >
{{ nfc_role_kubernetes_master | bool }}
when: >
item.when | default(true)
- name: Add sysctl net.ipv4.ip_forward
- name: Check if IPv6 Enabled
ansible.builtin.stat:
path: /proc/sys/net/ipv6/conf/all/disable_ipv6
register: ipv6_file
failed_when: false
- name: Add sysctl settings
ansible.posix.sysctl:
name: "{{ item.name }}"
value: "{{ item.value }}"
@ -108,8 +154,11 @@
value: '512'
- name: net.ipv6.conf.all.disable_ipv6
value: '1'
when:
- ansible_os_family == 'Debian'
when: "{{ ipv6_file.stat.exists }}"
when: >
ansible_os_family == 'Debian'
and
item.when | default(true) | bool
- name: Check for Network Manager Directory
@ -138,28 +187,245 @@
when: directory_network_manager_metadata.stat.exists
- name: Check if K3s Installed
- name: File Metadata - k3s binary
ansible.builtin.stat:
checksum_algorithm: sha256
name: /usr/local/bin/k3s
register: metadata_file_k3s_existing_binary
- name: File Metadata - k3s[-agent].service
ansible.builtin.stat:
checksum_algorithm: sha256
name: |-
/etc/systemd/system/k3s
{%- if not nfc_role_kubernetes_master | default(false) | bool -%}
-agent
{%- endif -%}
.service
register: metadata_file_k3s_service
- name: Directory Metadata - /etc/rancher/k3s/k3s.yaml
ansible.builtin.stat:
name: /etc/rancher/k3s/k3s.yaml
register: metadata_dir_etc_k3s
- name: File Metadata - /var/lib/rancher/k3s/server/token
ansible.builtin.stat:
checksum_algorithm: sha256
name: /var/lib/rancher/k3s/server/token
register: metadata_file_var_k3s_token
- name: Config Link
ansible.builtin.shell:
cmd: |
if [[ $(service k3s status) ]]; then exit 0; else exit 1; fi
executable: /bin/bash
changed_when: false
failed_when: false
register: k3s_installed
cmd: >
ln -s /etc/rancher/k3s/k3s.yaml ~/.kube/config
executable: bash
creates: ~/.kube/config
when: >
nfc_role_kubernetes_master | default(false) | bool
and
metadata_dir_etc_k3s.stat.exists | default(false) | bool
- name: Check if K3s Installed
- name: Fetch Kubernetes Node Object
kubernetes.core.k8s_info:
kind: Node
name: "{{ inventory_hostname }}"
register: kubernetes_node
when: >
metadata_file_k3s_existing_binary.stat.exists | default(false) | bool
and
metadata_file_k3s_service.stat.exists | default(false) | bool
and
metadata_dir_etc_k3s.stat.exists | default(false) | bool
and
metadata_file_var_k3s_token.stat.exists | default(false) | bool
- name: Fetch Installed K3s Metadata
ansible.builtin.shell:
cmd: |
if [[ $(service k3s-agent status) ]]; then exit 0; else exit 1; fi
export installed_version=$(k3s --version | grep k3s | awk '{print $3}');
export installed="
{%- if
metadata_file_k3s_existing_binary.stat.exists | default(false) | bool
and
metadata_file_k3s_service.stat.exists | default(false) | bool
and
metadata_dir_etc_k3s.stat.exists | default(false) | bool
and
metadata_file_var_k3s_token.stat.exists | default(false) | bool
-%}
true
{%- else -%}
false
{%- endif -%}";
if ! service k3s status > /dev/null; then
export installed='false';
fi
export running_version="{{ kubernetes_node.resources[0].status.nodeInfo.kubeletVersion | default('0') }}";
export correct_hash=$(wget -q https://github.com/k3s-io/k3s/releases/download/v
{{-KubernetesVersion + KubernetesVersion_k3s_prefix | urlencode -}}
/sha256sum-
{%- if ansible_architecture | lower == 'x86_64' -%}
amd64
{%- elif ansible_architecture | lower == 'aarch64' -%}
arm64
{%- endif %}.txt -O - | grep -v 'images' | awk '{print $1}');
cat <<EOF
{
"current_hash": "{{ metadata_file_k3s_existing_binary.stat.checksum | default('') }}",
"current_version": "${installed_version}",
"desired_hash": "${correct_hash}",
"desired_version": "v{{ KubernetesVersion + KubernetesVersion_k3s_prefix | default('') }}",
"installed": ${installed},
"running_version": "${running_version}"
}
EOF
executable: /bin/bash
changed_when: false
check_mode: false
failed_when: false
register: k3s_installed
register: k3s_metadata
- name: K3s Metadata Fact
ansible.builtin.set_fact:
node_k3s: "{{ k3s_metadata.stdout | from_yaml }}"
- name: Cached K3s Binary Details
ansible.builtin.stat:
path: "/tmp/k3s.{{ ansible_architecture }}"
checksum_algorithm: sha256
delegate_to: localhost
register: file_cached_k3s_binary
vars:
ansible_connection: local
- name: Remove Cached K3s Binaries
ansible.builtin.file:
path: "/tmp/k3s.{{ ansible_architecture }}"
state: absent
delegate_to: localhost
vars:
ansible_connection: local
when: >
not nfc_role_kubernetes_worker | default(false) | bool
file_cached_k3s_binary.stat.checksum | default('0') != node_k3s.desired_hash
- name: Try / Catch
block:
- name: Download K3s Binary
ansible.builtin.uri:
url: |-
https://github.com/k3s-io/k3s/releases/download/
{{- node_k3s.desired_version | urlencode -}}
/k3s
{%- if cpu_arch.key == 'aarch64' -%}
-arm64
{%- endif %}
method: GET
return_content: false
status_code:
- 200
- 304
dest: "/tmp/k3s.{{ ansible_architecture }}"
mode: "744"
changed_when: not ansible_check_mode
check_mode: false
delay: 10
retries: 3
register: k3s_download_files
delegate_to: localhost
failed_when: >
(lookup('ansible.builtin.file', '/tmp/k3s.' + ansible_architecture) | hash('sha256') | string) != node_k3s.desired_hash
and
(
k3s_download_files.status | int != 200
or
k3s_download_files.status | int != 304
)
run_once: true
when: ansible_os_family == 'Debian'
loop: "{{ nfc_kubernetes_install_architectures | dict2items }}"
loop_control:
loop_var: cpu_arch
vars:
ansible_connection: local
rescue:
- name: TRACE - Debug out
ansible.builtin.debug:
msg:
- "Download file hash: {{ (lookup('ansible.builtin.file', '/tmp/k3s.' + ansible_architecture) | hash('sha256') | string) }}"
- name: Fail task
ansible.builtin.assert:
that:
- false
msg: "Task failed, review previous task for error"
- name: Copy K3s binary to Host
ansible.builtin.copy:
src: "/tmp/k3s.{{ ansible_architecture }}"
dest: "/usr/local/bin/k3s"
mode: '741'
owner: root
group: root
register: k3s_binary_copy
when: >
node_k3s.current_hash != node_k3s.desired_hash
- name: K3s Binary Upgrade
ansible.builtin.service:
name: |-
{%- if nfc_role_kubernetes_master | default(false) | bool -%}
k3s
{%- else -%}
k3s-agent
{%- endif %}
state: restarted
register: k3s_upgrade_service_restart
when: >
(
k3s_binary_copy.changed | default(false) | bool
and
node_k3s.installed | default(false) | bool
)
or
(
node_k3s.running_version != node_k3s.desired_version
and
node_k3s.installed | default(false) | bool
)
- name: Create Fact - cluster_upgraded
ansible.builtin.set_fact:
nfc_role_kubernetes_cluster_upgraded: true
cacheable: true
when: >
k3s_upgrade_service_restart.changed | default(false) | bool
- name: Download Install Scripts
@ -172,7 +438,10 @@
- 304
dest: "{{ item.dest }}"
mode: "744"
check_mode: false
changed_when: false
delay: 10
retries: 3
register: k3s_download_script
delegate_to: localhost
run_once: true
@ -181,6 +450,8 @@
ansible_os_family == 'Debian'
and
item.when | default(true) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
loop: "{{ download_files }}"
vars:
ansible_connection: local
@ -192,61 +463,6 @@
when: "{{ nfc_role_kubernetes_install_olm }}"
- name: Download K3s Binary
ansible.builtin.uri:
url: |-
https://github.com/k3s-io/k3s/releases/download/v
{{- KubernetesVersion + KubernetesVersion_k3s_prefix | urlencode -}}
/k3s
{%- if cpu_arch.key == 'aarch64' -%}
-arm64
{%- endif %}
method: GET
return_content: false
status_code:
- 200
- 304
dest: "/tmp/k3s.{{ cpu_arch.key }}"
mode: "744"
changed_when: false
register: k3s_download_files
delegate_to: localhost
run_once: true
# no_log: true
when: ansible_os_family == 'Debian'
loop: "{{ nfc_kubernetes_install_architectures | dict2items }}"
loop_control:
loop_var: cpu_arch
vars:
ansible_connection: local
- name: "[TRACE] Downloaded File SHA256"
ansible.builtin.set_fact:
hash_sha256_k3s_downloaded_binary: "{{ lookup('ansible.builtin.file', '/tmp/k3s.' + cpu_arch.key) | hash('sha256') | string }}"
delegate_to: localhost
loop: "{{ nfc_kubernetes_install_architectures | dict2items }}"
loop_control:
loop_var: cpu_arch
- name: Existing k3s File hash
ansible.builtin.stat:
checksum_algorithm: sha256
name: /usr/local/bin/k3s
register: hash_sha256_k3s_existing_binary
- name: Copy K3s binary to Host
ansible.builtin.copy:
src: "/tmp/k3s.{{ ansible_architecture }}"
dest: "/usr/local/bin/k3s"
mode: '741'
owner: root
group: root
when: hash_sha256_k3s_existing_binary.stat.checksum | default('0') != hash_sha256_k3s_downloaded_binary
- name: Copy install scripts to Host
ansible.builtin.copy:
src: "{{ item.path }}"
@ -263,6 +479,8 @@
when: "{{ nfc_role_kubernetes_install_olm }}"
when: >
item.when | default(true) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Required Initial config files
@ -276,7 +494,8 @@
loop: "{{ k3s.files }}"
when: >
item.when | default(true) | bool
# kubernetes_config.cluster.prime.name == inventory_hostname
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Copy Intial required templates
@ -291,6 +510,8 @@
diff: true
when: >
item.when | default(true) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
vars:
templates_to_apply:
- src: k3s-config.yaml.j2
@ -300,7 +521,7 @@
dest: /var/lib/rancher/k3s/server/manifests/calico.yaml
when: >
{{
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
(
(
@ -308,7 +529,7 @@
and
file_calico_yaml_metadata.stat.exists
and
k3s_installed.rc == 0
not node_k3s.installed | bool
)
or
'calico_manifest' in ansible_run_tags
@ -331,23 +552,35 @@
# ipv6: true
- name: Set IP6Tables to legacy mode
ansible.builtin.command:
cmd: update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
changed_when: false
when: >
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Set IPTables to legacy mode
ansible.builtin.command:
cmd: update-alternatives --set iptables /usr/sbin/iptables-legacy
changed_when: false
when: >
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Install K3s (prime master)
ansible.builtin.shell:
cmd: |
INSTALL_K3S_SKIP_DOWNLOAD=true \
INSTALL_K3S_VERSION="v{{ KubernetesVersion }}{{ KubernetesVersion_k3s_prefix }}" \
INSTALL_K3S_VERSION="{{ node_k3s.desired_version }}" \
/tmp/install.sh {% if nfc_role_kubernetes_etcd_enabled %}--cluster-init{% endif %}
changed_when: false
when: >
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
k3s_installed.rc == 1
not node_k3s.installed | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Install Calico Operator
@ -364,12 +597,14 @@
'operator_calico' in ansible_run_tags
)
or
not file_calico_yaml_metadata.stat.exists
not file_calico_yaml_metadata.stat.exists | default(false)
)
and
'calico_manifest' not in ansible_run_tags
and
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Install MetalLB Operator
@ -388,7 +623,9 @@
when: >-
nfc_kubernetes_enable_metallb | default(false) | bool
and
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Wait for kubernetes prime to be ready
@ -402,7 +639,7 @@
exit 127;
fi
executable: /bin/bash
delegate_to: "{{ kubernetes_config.cluster.prime.name | default(inventory_hostname) }}"
delegate_to: "{{ nfc_role_kubernetes_node_prime }}"
run_once: true
register: kubernetes_ready_check
retries: 30
@ -413,6 +650,22 @@
kubernetes_ready_check.rc != 0
changed_when: false
failed_when: kubernetes_ready_check.rc != 0
when: >
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
and
not ansible_check_mode
- name: Config Link
ansible.builtin.shell:
cmd: >
ln -s /etc/rancher/k3s/k3s.yaml ~/.kube/config
executable: bash
creates: ~/.kube/config
when: >
nfc_role_kubernetes_master | default(false) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Install olm
@ -426,9 +679,11 @@
install_olm.rc == 1
register: install_olm
when: >
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
nfc_role_kubernetes_install_olm | default(false) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Uninstall OLM
@ -454,9 +709,11 @@
failed_when: false
register: install_olm
when: >
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
'olm_uninstall' in ansible_run_tags
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Enable Cluster Encryption
@ -465,10 +722,12 @@
changed_when: false
failed_when: false # New cluster will fail
when: >
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | bool
and
kubernetes_config.cluster.networking.encrypt | default(false) | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
and
(
'calico_manifest' in ansible_run_tags
or
@ -483,18 +742,22 @@
- name: Fetch Join Token
ansible.builtin.slurp:
src: /var/lib/rancher/k3s/server/token
delegate_to: "{{ kubernetes_config.cluster.prime.name | default(inventory_hostname) }}"
delegate_to: "{{ nfc_role_kubernetes_node_prime }}"
run_once: true
register: k3s_join_token
no_log: true # Value is sensitive
when: >
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Create Token fact
ansible.builtin.set_fact:
k3s_join_token: "{{ k3s_join_token.content | b64decode | replace('\n', '') }}"
delegate_to: "{{ kubernetes_config.cluster.prime.name | default(inventory_hostname) }}"
delegate_to: "{{ nfc_role_kubernetes_node_prime }}"
run_once: true
no_log: true # Value is sensitive
when: >
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Install K3s (master nodes)
@ -502,7 +765,7 @@
cmd: |
INSTALL_K3S_EXEC="server" \
INSTALL_K3S_SKIP_DOWNLOAD=true \
INSTALL_K3S_VERSION="v{{ KubernetesVersion }}{{ KubernetesVersion_k3s_prefix }}" \
INSTALL_K3S_VERSION="{{ node_k3s.desired_version }}" \
K3S_TOKEN="{{ k3s_join_token }}" \
/tmp/install.sh
executable: /bin/bash
@ -510,9 +773,11 @@
when: >
nfc_role_kubernetes_master | default(false) | bool
and
not kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
not nfc_role_kubernetes_prime | bool
and
k3s_installed.rc == 1
not node_k3s.installed | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Install K3s (worker nodes)
@ -521,18 +786,20 @@
set -o pipefail
INSTALL_K3S_EXEC="agent" \
INSTALL_K3S_SKIP_DOWNLOAD=true \
INSTALL_K3S_VERSION="v{{ KubernetesVersion }}{{ KubernetesVersion_k3s_prefix }}" \
INSTALL_K3S_VERSION="v{{ node_k3s.desired_version }}" \
K3S_TOKEN="{{ k3s_join_token }}" \
K3S_URL="https://{{ hostvars[kubernetes_config.cluster.prime.name | default(inventory_hostname)].ansible_host }}:6443" \
K3S_URL="https://{{ hostvars[nfc_role_kubernetes_node_prime].ansible_host }}:6443" \
/tmp/install.sh -
executable: /bin/bash
changed_when: false
when: >
not nfc_role_kubernetes_master | default(false) | bool
and
not kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
not nfc_role_kubernetes_prime | bool
and
k3s_installed.rc == 1
not node_k3s.installed | bool
and
not nfc_role_kubernetes_cluster_upgraded | default(false) | bool
- name: Set Kubernetes Final Install Fact

View File

@ -110,6 +110,7 @@
owner: root
group: 'root'
changed_when: false
check_mode: false
become: true
delegate_to: localhost
loop: "{{ nfc_kubernetes_install_architectures | dict2items }}"

View File

@ -1,14 +1,30 @@
---
- name: Default Variable adjustment [Probable Single Node Install]
ansible.builtin.set_fact:
cacheable: false
nfc_role_kubernetes_prime: true
nfc_role_kubernetes_master: true
nfc_role_kubernetes_node_prime: "{{ inventory_hostname }}"
when: >
not nfc_role_kubernetes_worker | bool
and
not nfc_role_kubernetes_prime | bool
and
not nfc_role_kubernetes_master | bool
- name: Install/Configure Kubernetes Prime Master Node
ansible.builtin.include_tasks:
file: install.yaml
tags:
- always
when:
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
and
nfc_role_kubernetes_prime | bool
and
not nfc_role_kubernetes_worker | bool
and
not kubernetes_installed | default(false)
- name: Install/Configure Kubernetes on remaining Master Nodes
@ -17,9 +33,13 @@
tags:
- always
when:
kubernetes_config.cluster.prime.name | default(inventory_hostname) != inventory_hostname
and
nfc_role_kubernetes_master | bool
and
not nfc_role_kubernetes_prime | bool
and
not nfc_role_kubernetes_worker | bool
and
not kubernetes_installed | default(false)
- name: Install/Configure Kubernetes on Worker Nodes
@ -33,3 +53,5 @@
not nfc_role_kubernetes_prime | bool
and
not nfc_role_kubernetes_master | bool
and
not kubernetes_installed | default(false)

View File

@ -1,7 +1,7 @@
#
# IP Tables Firewall Rules for Kubernetes
#
# Managed By ansible/role/nfc_kubernetes
# Managed By ansible/collection/kubernetes
#
# Dont edit this file directly as it will be overwritten. To grant a host API access
# edit the cluster config, adding the hostname/ip to path kubernetes_config.cluster.access
@ -61,7 +61,7 @@
{%- if kubernetes_host != '' -%}
{%- for master_host in groups['kubernetes_master'] -%}
{%- for master_host in groups['kubernetes_master'] | default([]) -%}
{%- if master_host in groups[kubernetes_config.cluster.group_name | default('me_is_optional')] | default([]) -%}
@ -149,8 +149,13 @@
{#- All cluster Hosts -#}
{%- if nfc_role_kubernetes_master | default(false) | bool -%}
{%- if
nfc_role_kubernetes_master | default(false) | bool
and
kubernetes_host not in groups['kubernetes_master']
and
'-I kubernetes-api -s ' + kubernetes_host + ' -j ACCEPT' not in data.firewall_rules
-%}
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-api -s ' + kubernetes_host + ' -j ACCEPT'] -%}
@ -162,9 +167,17 @@
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-flannel-wg-four -s ' + kubernetes_host + ' -j ACCEPT'] -%}
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-flannel-wg-six -s ' + kubernetes_host + ' -j ACCEPT'] -%}
{%- if false -%}{# see IPv6 is disabled #}
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-flannel-wg-six -s ' + kubernetes_host + ' -j ACCEPT'] -%}
{%- endif -%}
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-calico-bgp -s ' + kubernetes_host + ' -j ACCEPT'] -%}
{%- if false -%}{# see Installation-manifest-Calico_Cluster.yaml.j2 bgp is disabled #}
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-calico-bgp -s ' + kubernetes_host + ' -j ACCEPT'] -%}
{%- endif -%}
{%- set data.firewall_rules = data.firewall_rules + ['-I kubernetes-calico-typha -s ' + kubernetes_host + ' -j ACCEPT'] -%}

View File

@ -7,11 +7,12 @@
#
{%- if
inventory_hostname in groups['kubernetes_master']
nfc_role_kubernetes_master
or
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
nfc_role_kubernetes_prime | default(true) | bool
and
not nfc_role_kubernetes_worker
-%}
{%
set kube_apiserver_arg = [
@ -128,6 +129,16 @@
{# SoF All Nodes #}
{%- if inventory_hostname == 'localhost' -%}
{%- set node_name = hostname_to_check.stdout -%}
{%- else -%}
{%- set node_name = inventory_hostname -%}
{%- endif -%}
{%
set all_nodes_config = {
@ -135,7 +146,8 @@
"system-reserved=cpu=" + kubelet_arg_system_reserved_cpu + ",memory=" + kubelet_arg_system_reserved_memory +
",ephemeral-storage=" + kubelet_arg_system_reserved_storage
],
"node-name": inventory_hostname,
"node-name": node_name,
"resolv-conf": nfc_role_kubernetes_resolv_conf_file,
}
-%}
@ -143,13 +155,13 @@
{%- if groups[kubernetes_config.cluster.group_name | default('make_me_optional')] | default([]) | list | length > 0 -%}
{%- if k3s_installed.rc == 0 -%}
{%- if node_k3s.installed -%}
{%- set ns = namespace(server=[]) -%}
{%- for cluster_node in groups[kubernetes_config.cluster.group_name] -%}
{%- if cluster_node in groups['kubernetes_master'] -%}
{%- if cluster_node in groups['kubernetes_master'] | default([]) -%}
{%- if hostvars[cluster_node].host_external_ip is defined -%}
@ -186,13 +198,28 @@
}) -%}
{%- elif
kubernetes_config.cluster.prime.name != inventory_hostname
nfc_role_kubernetes_prime | default(true) | bool
and
k3s_installed.rc == 1
not node_k3s.installed
and
not nfc_role_kubernetes_worker
-%}
{%- set ns = namespace(prime_name) -%}
{%- for hostname, values in hostvars.iteritems() -%}
{%- if values.nfc_role_kubernetes_node_prime ==true -%}
{%- set ns.prime_name = hostname -%}
{%- endif -%}
{%- endfor -%}
{%- set server = (server | default([])) + [
"https://" + hostvars[kubernetes_config.cluster.prime.name].ansible_host + ":6443"
"https://" + ns.prime_name.ansible_host + ":6443"
] -%}
{%- set all_nodes_config = all_nodes_config | combine({
@ -224,13 +251,18 @@
{%- endif -%}
{# EoF All Nodes #}
{%- if
inventory_hostname in groups['kubernetes_master']
or
kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname
(
nfc_role_kubernetes_master
or
nfc_role_kubernetes_prime | default(true) | bool
)
and
not nfc_role_kubernetes_worker
-%}
{%- set servers_config = servers_config | combine( all_nodes_config ) -%}

View File

@ -0,0 +1,90 @@
---
kubernetes_chains:
- name: kubernetes-embedded-etcd
chain: true
table: INPUT
protocol: tcp
dest:
port:
- '2379'
- '2380'
comment: etcd. Servers only
when: "{{ nfc_role_kubernetes_etcd_enabled }}"
- name: kubernetes-api
chain: true
table: INPUT
protocol: tcp
dest:
port: '6443'
comment: Kubernetes API access. All Cluster hosts and end users
- name: kubernetes-calico-bgp
chain: true
table: INPUT
protocol: tcp
dest:
port: '179'
comment: Kubernetes Calico BGP. All Cluster hosts and end users
when: false # currently hard set to false. see Installation-manifest-Calico_Cluster.yaml.j2
- name: kubernetes-flannel-vxlan
chain: true
table: INPUT
protocol: udp
dest:
port: '4789'
comment: Flannel. All cluster hosts
- name: kubernetes-kubelet-metrics
chain: true
table: INPUT
protocol: tcp
dest:
port: '10250'
comment: Kubernetes Metrics. All cluster hosts
- name: kubernetes-flannel-wg-four
chain: true
table: INPUT
protocol: udp
dest:
port: '51820'
comment: Flannel Wiregaurd IPv4. All cluster hosts
- name: kubernetes-flannel-wg-six
chain: true
table: INPUT
protocol: udp
dest:
port: '51821'
comment: Flannel Wiregaurd IPv6. All cluster hosts
when: false # ipv6 is disabled. see install.yaml sysctrl
- name: kubernetes-calico-typha
chain: true
table: INPUT
protocol: tcp
dest:
port: '5473'
comment: Calico networking with Typha enabled. Typha agent hosts.
- name: metallb-l2-tcp
chain: true
table: INPUT
protocol: tcp
dest:
port: '7946'
comment: MetalLB Gossip
when: "{{ nfc_kubernetes_enable_metallb }}"
- name: metallb-l2-udp
chain: true
table: INPUT
protocol: udp
dest:
port: '7946'
comment: MetalLB Gossip
when: "{{ nfc_kubernetes_enable_metallb }}"