tuana9a / kp

a kubernetes proxmox cli

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kp

a kubernetes proxmox cli

Prepare the network for vm

ssh into the proxmox host

vim /etc/network/interfaces

Add these line to add a new NAT network with cidr 192.168.56.1/24

auto vmbr56
iface vmbr56 inet static
        address 192.168.56.1/24
        bridge-ports none
        bridge-stp off
        bridge-fd 0
        post-up   iptables -t nat -A POSTROUTING -s '192.168.56.0/24' -o vmbr0 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '192.168.56.0/24' -o vmbr0 -j MASQUERADE

Prefare vm template

Install tools to build image

apt install libguestfs-tools

Download base image

base_img_file=jammy-server-cloudimg-amd64.img
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img -O $base_img_file

Installing qemu-guest-agent is required

base_img_file=jammy-server-cloudimg-amd64.img
img_file=jammy.img
cp $base_img_file $img_file
virt-customize -a $img_file --install qemu-guest-agent
img_file=jammy.img
storage=local-lvm
vmid=9999
core_count=4
mem_size=8192

qm create $vmid --cores $core_count --memory $mem_size --scsihw virtio-scsi-pci
qm set $vmid --name jammy
qm set $vmid --scsi0 $storage:0,import-from=$PWD/$img_file
qm set $vmid --ide2 $storage:cloudinit
qm set $vmid --boot order=scsi0
qm set $vmid --serial0 socket --vga serial0
qm template $vmid

Prepare the config.json

See ./app/payload.py#Cfg

Code structure

graph TD;
  cli-->service;
  cli-->model;
  service-->model;
  service-->util;
  cli-->util;
  model-->util;
  util-->config;
  util-->logger;
  payload-->config;
  model-->payload;
  util-->payload;
  service-->payload;
  model-->config;
  service-->config;
  cli-->config;
  service-->error;
  model-->error;
  error;
Loading

[WIP] How to use

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

build it

pyinstaller --name kp --onefile --hidden-import proxmoxer.backends --hidden-import proxmoxer.backends.https main.py
sudo ln -sf $PWD/dist/kp /usr/local/bin/kp
sudo chmod +x /usr/local/bin/kp

Decision / Choise / Explain

Immutable infrastructure

  • converting worker to control plane or in reverse is not straight forward, as kubeadm reset leave cni (network), iptables behind so instead of modifing the node just remove it and create a new one.
  • when upgrading the k8s, upgrade in-place for worker node is not a must, we can just drain it, remove it, destroy it then create a new one with installed newer k8s verion.

About

a kubernetes proxmox cli

License:GNU General Public License v3.0


Languages

Language:Python 99.9%Language:Shell 0.1%