Compare commits
36 Commits
fix/ansibl
...
3f0c8a865d
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f0c8a865d | |||
| 3f2e6d86f6 | |||
| 08560c945b | |||
| 506a9b32d9 | |||
| d4ece741e0 | |||
| 311a592d6e | |||
| 153ea8e982 | |||
| 943e9651da | |||
| 669c414288 | |||
| e3afed5e4f | |||
| e337989a59 | |||
| 7f36ff272e | |||
| 79e6698db1 | |||
| 603559b255 | |||
| 4851b6521c | |||
| 9785e8a40a | |||
| 79bd7424c3 | |||
| 5227bea568 | |||
| 47b69d7f49 | |||
| a3fdc5fcc7 | |||
| 5a1afb4a07 | |||
| e03daa62e5 | |||
| 15dfaea8db | |||
| ef4967cd88 | |||
| 55217ce50b | |||
| 2bbc9095f7 | |||
| fcf7ded218 | |||
| b68d53b143 | |||
| 3c6bc90feb | |||
| 3521b840ae | |||
| 5f10976264 | |||
| 10e936a8da | |||
| 8bbaea8fd9 | |||
| d39e0c04e5 | |||
| b99525955e | |||
| 9b6f9b6656 |
3
ansible/inventory.yaml
Normal file
3
ansible/inventory.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
nigel:
|
||||||
|
hosts:
|
||||||
|
nigel.local:
|
||||||
4
ansible/linter.yaml
Normal file
4
ansible/linter.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
skip_list:
|
||||||
|
- role-name
|
||||||
|
- var-naming[no-role-prefix]
|
||||||
27
ansible/local-setup-admin-user.yaml
Normal file
27
ansible/local-setup-admin-user.yaml
Normal 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
|
||||||
12
ansible/nuc.yaml
Normal file
12
ansible/nuc.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
- hosts: nigel.local
|
||||||
|
remote_user: nigel
|
||||||
|
tasks:
|
||||||
|
- name: Setup basic role on nigel
|
||||||
|
tags:
|
||||||
|
- setup
|
||||||
|
- nomad
|
||||||
|
- proxy
|
||||||
|
- volumes
|
||||||
|
ansible.builtin.include_role:
|
||||||
|
name: local-server-head
|
||||||
1
ansible/roles/local-server-head/files/docker.list
Normal file
1
ansible/roles/local-server-head/files/docker.list
Normal file
@@ -0,0 +1 @@
|
|||||||
|
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu noble stable
|
||||||
15
ansible/roles/local-server-head/files/host-file
Normal file
15
ansible/roles/local-server-head/files/host-file
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
127.0.0.1 localhost
|
||||||
|
127.0.1.1 nigel
|
||||||
|
|
||||||
|
# Our own dns stuff
|
||||||
|
127.0.1.1 nigel.local
|
||||||
|
127.0.1.1 nomad.nigel.local
|
||||||
|
127.0.1.1 sanity.nigel.local
|
||||||
|
127.0.1.1 ncr.nigel.local
|
||||||
|
|
||||||
|
# The following lines are desirable for IPv6 capable hosts
|
||||||
|
::1 ip6-localhost ip6-loopback
|
||||||
|
fe00::0 ip6-localnet
|
||||||
|
ff00::0 ip6-mcastprefix
|
||||||
|
ff02::1 ip6-allnodes
|
||||||
|
ff02::2 ip6-allrouters
|
||||||
6
ansible/roles/local-server-head/files/ncr.conf
Normal file
6
ansible/roles/local-server-head/files/ncr.conf
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
server {
|
||||||
|
server_name ncr.nigel.local;
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:5000;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
ansible/roles/local-server-head/files/nomad.conf
Normal file
25
ansible/roles/local-server-head/files/nomad.conf
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
server {
|
||||||
|
server_name nomad.nigel.local;
|
||||||
|
location / {
|
||||||
|
proxy_pass http://nomad-ws;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
|
proxy_read_timeout 319s;
|
||||||
|
|
||||||
|
# This is for log streaming requests
|
||||||
|
proxy_buffering off;
|
||||||
|
|
||||||
|
# Upgrade and Connection headers for upgrading to websockets
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
|
|
||||||
|
proxy_set_header Origin "${scheme}://${proxy_host}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
upstream nomad-ws {
|
||||||
|
ip_hash;
|
||||||
|
server nomad.nigel.local:4646;
|
||||||
|
}
|
||||||
7
ansible/roles/local-server-head/files/sanity.conf
Normal file
7
ansible/roles/local-server-head/files/sanity.conf
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
server {
|
||||||
|
server_name sanity.nigel.local;
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:8080;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
- name: Ensure we have basic updated packages setting up docker
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: "{{ item }}"
|
||||||
|
update_cache: true
|
||||||
|
loop:
|
||||||
|
- ca-certificates
|
||||||
|
- curl
|
||||||
|
- name: Running install on the keyrings directory
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: install -m 0755 -d /etc/apt/keyrings
|
||||||
|
register: install
|
||||||
|
changed_when: install.rc == 0
|
||||||
|
- name: Fetch Docker GPG Key
|
||||||
|
vars:
|
||||||
|
keylink: https://download.docker.com/linux/ubuntu/gpg
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ keylink }}"
|
||||||
|
dest: /etc/apt/keyrings/docker.asc
|
||||||
|
mode: "0644"
|
||||||
|
- name: Add repo to apt sources
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: docker.list
|
||||||
|
dest: /etc/apt/sources.list.d/docker.list
|
||||||
|
mode: "0644"
|
||||||
|
- name: Update Apt cache with latest docker.list packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: true
|
||||||
|
- name: Ensure all docker packages are updated to the latest versions
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: "{{ item }}"
|
||||||
|
loop:
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
- name: Verify that the docker components are installed properly
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: docker run hello-world
|
||||||
|
register: docker
|
||||||
|
changed_when: docker.rc == 0
|
||||||
41
ansible/roles/local-server-head/tasks/main.yaml
Normal file
41
ansible/roles/local-server-head/tasks/main.yaml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
- name: Ensure docker components are installed
|
||||||
|
tags:
|
||||||
|
- setup
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: ensure-docker-basic.yaml
|
||||||
|
apply:
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- setup
|
||||||
|
- name: Ensure nigel can use sudo without password
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- setup
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/sudoers
|
||||||
|
state: present
|
||||||
|
line: "nigel ALL=(ALL) NOPASSWD:ALL"
|
||||||
|
- name: Run through nomad installation steps
|
||||||
|
tags: nomad
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: nomad.yaml
|
||||||
|
apply:
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- nomad
|
||||||
|
- name: Setup the reverse proxy outside of nomad
|
||||||
|
tags: proxy
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: reverse_proxy.yaml
|
||||||
|
apply:
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- proxy
|
||||||
|
- name: Setup data directory for the nomad host volumes
|
||||||
|
tags: volumes
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: nomad-host-volumes.yaml
|
||||||
|
apply:
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- volumes
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
- name: Ensure the root data directory is present
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ host_vol_root }}"
|
||||||
|
state: directory
|
||||||
|
- name: Ensure registry volume is present
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ host_vol_root }}/ncr"
|
||||||
|
state: directory
|
||||||
54
ansible/roles/local-server-head/tasks/nomad.yaml
Normal file
54
ansible/roles/local-server-head/tasks/nomad.yaml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
- name: Ensure prerequisite packages are installed
|
||||||
|
ansible.builtin.apt:
|
||||||
|
pkg:
|
||||||
|
- wget
|
||||||
|
- gpg
|
||||||
|
- coreutils
|
||||||
|
update_cache: true
|
||||||
|
- name: Hashicorp repo setup
|
||||||
|
vars:
|
||||||
|
keypath: /usr/share/keyrings/hashicorp-archive-keyring.gpg
|
||||||
|
gpgpath: /tmp/hashicorp.gpg
|
||||||
|
block:
|
||||||
|
- name: Download the hashicorp GPG Key
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: https://apt.releases.hashicorp.com/gpg
|
||||||
|
dest: "{{ gpgpath }}"
|
||||||
|
- name: Dearmor the hashicorp gpg key
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: "gpg --dearmor --yes -o {{ keypath }} {{ gpgpath }}"
|
||||||
|
register: gpg
|
||||||
|
changed_when: gpg.rc == 0
|
||||||
|
- name: Add the hashicorp linux repo
|
||||||
|
vars:
|
||||||
|
keyfile: "{{ keypath }}"
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: hashicorp.list
|
||||||
|
dest: /etc/apt/sources.list.d/hashicorp.list
|
||||||
|
mode: "0644"
|
||||||
|
- name: Update apt repo cache
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: true
|
||||||
|
- name: Install consul
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: consul
|
||||||
|
- name: Install nomad package
|
||||||
|
ansible.builtin.apt:
|
||||||
|
pkg: nomad
|
||||||
|
- name: Copy in the consul configuration
|
||||||
|
vars:
|
||||||
|
ip: "{{ ansible_default_ipv4['address'] }}"
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: consul.hcl
|
||||||
|
dest: /etc/consul.d/consul.hcl
|
||||||
|
mode: "0644"
|
||||||
|
- name: Start nomad
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: nomad
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
- name: Make sure the consul service is NOT available
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: consul
|
||||||
|
state: stopped
|
||||||
|
enabled: true
|
||||||
31
ansible/roles/local-server-head/tasks/reverse_proxy.yaml
Normal file
31
ansible/roles/local-server-head/tasks/reverse_proxy.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
- name: Keep /etc/hosts up to date
|
||||||
|
ansible.builtin.copy:
|
||||||
|
dest: /etc/hosts
|
||||||
|
src: host-file
|
||||||
|
mode: "0644"
|
||||||
|
- name: Ensure nginx is setup as latest
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: nginx
|
||||||
|
- name: Copy the nomad.conf to available configurations
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ item }}"
|
||||||
|
dest: "/etc/nginx/sites-available/{{ item }}"
|
||||||
|
mode: "0644"
|
||||||
|
loop:
|
||||||
|
- nomad.conf
|
||||||
|
- sanity.conf
|
||||||
|
- ncr.conf
|
||||||
|
- name: Link the nomad.conf to sites-enabled
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/etc/nginx/sites-enabled/{{ item }}"
|
||||||
|
state: link
|
||||||
|
src: "/etc/nginx/sites-available/{{ item }}"
|
||||||
|
mode: "0644"
|
||||||
|
loop:
|
||||||
|
- nomad.conf
|
||||||
|
- sanity.conf
|
||||||
|
- ncr.conf
|
||||||
|
- name: Restart nginx
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: nginx
|
||||||
|
state: restarted
|
||||||
12
ansible/roles/local-server-head/templates/consul.hcl
Normal file
12
ansible/roles/local-server-head/templates/consul.hcl
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
bind_addr = "{{ ip }}"
|
||||||
|
advertise_addr = "{{ ip }}"
|
||||||
|
bootstrap = true
|
||||||
|
bootstrap_expect = 1
|
||||||
|
client_addr = "{{ ip }}"
|
||||||
|
server = true
|
||||||
|
data_dir = "/opt/consul"
|
||||||
|
|
||||||
|
ui_config {
|
||||||
|
enabled = true
|
||||||
|
}
|
||||||
|
|
||||||
1
ansible/roles/local-server-head/templates/hashicorp.list
Normal file
1
ansible/roles/local-server-head/templates/hashicorp.list
Normal file
@@ -0,0 +1 @@
|
|||||||
|
deb [signed-by={{ keyfile }}] https://apt.releases.hashicorp.com jammy main
|
||||||
1
ansible/roles/local-server-head/vars/main.yaml
Normal file
1
ansible/roles/local-server-head/vars/main.yaml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
host_vol_root: /opt/volumes
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
bucket="$1"
|
|
||||||
s3env=/opt/nginx/s3.env
|
|
||||||
|
|
||||||
[[ -z "$bucket" ]] && echo "No bucket selected" && exit 1
|
|
||||||
|
|
||||||
[[ ! -f $s3env ]] && echo "No credentials to source!" && exit 1
|
|
||||||
source $s3env
|
|
||||||
|
|
||||||
pull() {
|
|
||||||
aws s3 sync s3://$bucket /opt/nginx/$bucket
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case $bucket in
|
|
||||||
resume.shockrah.xyz|shockrah.xyz|temper.tv) pull;;
|
|
||||||
*) echo "Invalid bucket name" && exit 1 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
4
infra/containers/sanity-nginx/Dockerfile
Normal file
4
infra/containers/sanity-nginx/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Because I just really needed ok?
|
||||||
|
FROM nginx:latest
|
||||||
|
|
||||||
|
COPY default /etc/nginx/conf.d/default.conf
|
||||||
15
infra/containers/sanity-nginx/default
Normal file
15
infra/containers/sanity-nginx/default
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
server {
|
||||||
|
listen 8080;
|
||||||
|
listen [::]:8080;
|
||||||
|
server_name localhost;
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
opt=$1
|
|
||||||
plan=tfplan
|
|
||||||
|
|
||||||
build_plan() {
|
|
||||||
echo Generating plan
|
|
||||||
set -x
|
|
||||||
terraform plan -var-file variables.tfvars -input=false -out $plan
|
|
||||||
}
|
|
||||||
|
|
||||||
deploy_plan() {
|
|
||||||
terraform apply $plan
|
|
||||||
}
|
|
||||||
|
|
||||||
init() {
|
|
||||||
terraform init
|
|
||||||
}
|
|
||||||
|
|
||||||
help_prompt() {
|
|
||||||
cat <<- EOF
|
|
||||||
Options: plan deploy help
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# Default to building a plan
|
|
||||||
source ./secrets.sh
|
|
||||||
case $opt in
|
|
||||||
plan) build_plan;;
|
|
||||||
deploy) deploy_plan;;
|
|
||||||
*) help_prompt;;
|
|
||||||
esac
|
|
||||||
@@ -37,6 +37,7 @@ locals {
|
|||||||
{ name = "www.shockrah.xyz", records = [ var.vultr_host ] },
|
{ name = "www.shockrah.xyz", records = [ var.vultr_host ] },
|
||||||
{ name = "resume.shockrah.xyz", records = [ var.vultr_host ] },
|
{ name = "resume.shockrah.xyz", records = [ var.vultr_host ] },
|
||||||
{ name = "git.shockrah.xyz", records = [ var.vultr_host ] },
|
{ name = "git.shockrah.xyz", records = [ var.vultr_host ] },
|
||||||
|
{ name = "lmao.shockrah.xyz", records = [ "207.246.107.99" ] },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
infra/nigel-nomad/sanity-service.nomad.hcl
Normal file
30
infra/nigel-nomad/sanity-service.nomad.hcl
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# This 'service' job is just a simple nginx container that lives here as a kind of sanity check
|
||||||
|
# PORT: 8080
|
||||||
|
# DNS : sanity.nigel.local
|
||||||
|
job "health" {
|
||||||
|
type = "service"
|
||||||
|
|
||||||
|
group "health" {
|
||||||
|
count = 1
|
||||||
|
network {
|
||||||
|
port "http" {
|
||||||
|
static = 8080
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
service {
|
||||||
|
name = "health-svc"
|
||||||
|
port = "http"
|
||||||
|
provider = "nomad"
|
||||||
|
}
|
||||||
|
|
||||||
|
task "health-setup" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "shockrah/sanity:latest"
|
||||||
|
ports = [ "http" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
infra/static-vultr/tarpit.tf
Normal file
28
infra/static-vultr/tarpit.tf
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
resource tls_private_key tarpit {
|
||||||
|
algorithm = "RSA"
|
||||||
|
rsa_bits = 4096
|
||||||
|
}
|
||||||
|
|
||||||
|
resource vultr_ssh_key tarpit {
|
||||||
|
name = "tarpit_ssh_key"
|
||||||
|
ssh_key = chomp(tls_private_key.tarpit.public_key_openssh)
|
||||||
|
}
|
||||||
|
|
||||||
|
resource vultr_instance tarpit {
|
||||||
|
# Core configuration
|
||||||
|
plan = var.host.plan
|
||||||
|
region = var.host.region
|
||||||
|
os_id = var.host.os
|
||||||
|
enable_ipv6 = true
|
||||||
|
|
||||||
|
|
||||||
|
ssh_key_ids = [ vultr_ssh_key.host.id ]
|
||||||
|
firewall_group_id = vultr_firewall_group.host.id
|
||||||
|
label = "Tarpit"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
output tarpit_ssh_key {
|
||||||
|
sensitive = true
|
||||||
|
value = tls_private_key.host.private_key_pem
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user