Compare commits

...

4 Commits

Author SHA1 Message Date
8bbaea8fd9 Simple admin user setup on a clean buntu machine
Some checks failed
Ansible Linting / ansible-lint (push) Failing after 6s
Secops Linting and Safety Checks / checkov-scan-s3 (push) Failing after 17s
2025-04-11 02:43:22 -07:00
d39e0c04e5 Adding health to games selector set
Some checks failed
Ansible Linting / ansible-lint (push) Failing after 3s
Secops Linting and Safety Checks / checkov-scan-s3 (push) Failing after 14s
2025-02-10 22:11:09 -08:00
b99525955e Swapping health pod to admin-services 2025-02-10 22:10:46 -08:00
9b6f9b6656 Fixing tag issues with pod selector
Some checks failed
Ansible Linting / ansible-lint (push) Failing after 6s
Secops Linting and Safety Checks / checkov-scan-s3 (push) Failing after 18s
2025-02-10 22:10:02 -08:00
7 changed files with 55 additions and 27 deletions

3
ansible/inventory.yaml Normal file
View File

@ -0,0 +1,3 @@
nigel:
hosts:
nigel.local:

View File

@ -0,0 +1,27 @@
# This playbook is meant to be a oneshot to be ran manually on the dev box
# The rest of the role stuff is meant to be ran as the admin user that
# this playbook creates for us
---
- hosts: nigel.local
remote_user: nigel
vars:
admin:
username: nigel
tasks:
- name: Copy the nigel admin key
ansible.builtin.authorized_key:
user: "{{ admin.username }}"
state: present
key: "{{ lookup('file', '~/.ssh/nigel/admin.pub') }}"
- name: Prevent password based logins
become: true
ansible.builtin.lineinfile:
dest: /etc/ssh/sshd_config
line: PasswordAuthentication no
state: present
backup: true
- name: Restart SSH Daemon
become: true
ansible.builtin.service:
name: ssh
state: restarted

View File

@ -17,7 +17,7 @@ resource kubernetes_pod admin {
} }
spec { spec {
node_selector = { node_selector = {
NodeType = var.admin_services.namespace "vke.vultr.com/node-pool" = var.admin_services.namespace
} }
container { container {
image = each.value.image image = each.value.image

View File

@ -22,7 +22,7 @@ resource vultr_kubernetes_node_pools games {
label = var.game_servers.namespace label = var.game_servers.namespace
min_nodes = var.cluster.pools["games"].min min_nodes = var.cluster.pools["games"].min
max_nodes = var.cluster.pools["games"].max max_nodes = var.cluster.pools["games"].max
tag = var.admin_services.namespace tag = var.game_servers.namespace
} }
output k8s_config { output k8s_config {

View File

@ -8,7 +8,7 @@ def get_args() -> Namespace:
prog="Cluster Search Thing", prog="Cluster Search Thing",
description="General utility for finding resources for game server bot" description="General utility for finding resources for game server bot"
) )
games = {"reflex", "minecraft"} games = {"health", "reflex", "minecraft"}
parser.add_argument('-g', '--game', required=False, choices=games) parser.add_argument('-g', '--game', required=False, choices=games)
admin = {"health"} admin = {"health"}
@ -21,11 +21,19 @@ def k8s_api(config_path: str) -> client.api.core_v1_api.CoreV1Api:
def get_admin_service_details(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api): def get_admin_service_details(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api):
print('admin thing requested', args.admin) print('admin thing requested', args.admin)
services = api.list_service_for_all_namespaces(label_selector=f'app={args.admin}')
if len(services.items) == 0:
print(f'Unable to find {args.admin} amongst the admin-services')
return
port = services.items[0].spec.ports[0].port
node_ips = list(filter(lambda a: a.type == 'ExternalIP', api.list_node().items[0].status.addresses))
ipv4 = list(filter(lambda item: not re.match('[\d\.]{3}\d', item.address), node_ips))[0].address
ipv6 = list(filter(lambda item: re.match('[\d\.]{3}\d', item.address), node_ips))[0].address
print(f'{args.admin} --> {ipv4}:{port} ~~> {ipv6}:{port}')
def get_game_server_ip(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api): def get_game_server_ip(args: ArgumentParser, api: client.api.core_v1_api.CoreV1Api):
pods = api.list_pod_for_all_namespaces(label_selector=f'app={args.game}')
node_name = pods.items[0].spec.node_name
services = api.list_service_for_all_namespaces(label_selector=f'app={args.game}') services = api.list_service_for_all_namespaces(label_selector=f'app={args.game}')
port = services.items[0].spec.ports[0].port port = services.items[0].spec.ports[0].port

View File

@ -29,4 +29,3 @@ resource vultr_firewall_rule admin-service-inbound {
notes = each.value.port.notes notes = each.value.port.notes
port = each.value.port.expose port = each.value.port.expose
} }

View File

@ -21,31 +21,22 @@ cluster = {
game_servers = { game_servers = {
namespace = "games" namespace = "games"
configs = { configs = {
# minecraft = {
# image = "itzg/minecraft-server"
# cpu = "1000m"
# mem = "2048Mi"
# port = {
# expose = 30808
# internal = 80
# }
# }
} }
} }
admin_services = { admin_services = {
namespace = "admin-services" namespace = "admin-services"
configs = { configs = {
# health = { health = {
# image = "nginx:latest" image = "nginx:latest"
# name = "health" name = "health"
# cpu = "200m" cpu = "200m"
# mem = "64Mi" mem = "64Mi"
# port = { port = {
# notes = "Basic nginx sanity check service" notes = "Basic nginx sanity check service"
# expose = 30800 expose = 30800
# internal = 80 internal = 80
# } }
# } }
} }
} }