Skip to content

Commit

Permalink
image fixes! switched to the new ubuntu version
Browse files Browse the repository at this point in the history
  • Loading branch information
simonccc committed Aug 29, 2024
1 parent 2f3ec8a commit fb71c10
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# :burger: kopsrox
# :hamburger: kopsrox

- kopsrox is a script to automate creation and management of simple ha k3s cluster on ProxmoxVE using cloud images :nerd_face:
- add more master/worker k3s nodes using a simple config file and cli interface :pray:
Expand All @@ -15,4 +15,4 @@
# :boom: in progress
- Improving Docs
- Some code clean up
- Recent: bug fixes
- Recent: bug fixes, machine type optimisations, kubevip improvements
24 changes: 14 additions & 10 deletions dev/img-mirror/get.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
if [ ! -f mantic-minimal-cloudimg-amd64.img ]
# downloads image for use with serve.sh
ubr="oracular"
if [ ! -f "${ubr}-minimal-cloudimg-amd64.img" ]
then
wget https://cloud-images.ubuntu.com/minimal/daily/mantic/current/mantic-minimal-cloudimg-amd64.img
wget "https://cloud-images.ubuntu.com/minimal/daily/${ubr}/current/${ubr}-minimal-cloudimg-amd64.img"
fi
if [ ! -f amzn2-kvm-2.0.20240306.2-x86_64.xfs.gpt.qcow2 ]
then
wget https://cdn.amazonlinux.com/os-images/2.0.20240306.2/kvm/amzn2-kvm-2.0.20240306.2-x86_64.xfs.gpt.qcow2
fi
if [ ! -f Rocky-9-GenericCloud.latest.x86_64.qcow2 ]
then
wget https://mirrors.vinters.com/rocky/9/images/x86_64/Rocky-9-GenericCloud.latest.x86_64.qcow2
fi

# untested
#if [ ! -f amzn2-kvm-2.0.20240306.2-x86_64.xfs.gpt.qcow2 ]
#then
#wget https://cdn.amazonlinux.com/os-images/2.0.20240306.2/kvm/amzn2-kvm-2.0.20240306.2-x86_64.xfs.gpt.qcow2
#fi
#if [ ! -f Rocky-9-GenericCloud.latest.x86_64.qcow2 ]
#then
#wget https://mirrors.vinters.com/rocky/9/images/x86_64/Rocky-9-GenericCloud.latest.x86_64.qcow2
#fi
8 changes: 4 additions & 4 deletions docs/SETUP.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@


# :baby_symbol: setup
# :hamburger: kopsrox setup

## :hammer_and_wrench: requirements

- Proxmox VE with root access or a user who can 'sudo su' without a password
- network with internet access configured in proxmox as a bridge or a proxmox sdn network
- a range of 10 free Proxmox qm/virtual machine id 'vmids' eg 600 to 610
- a range of 10 IP's on a network for kopsrox to work with eg 192.168.0.160 to 192.168.0.170
- a range of 10 IP's on a network with internet access for kopsrox to work with eg 192.168.0.160 to 192.168.0.170
- clone the repo and follow the steps below

## :bricks: install packages
Expand All @@ -17,6 +15,8 @@

_installs the required pip packages vs using os packages_

( this will be improved in the future )

## :star: generate api key

`sudo pvesh create /access/users/root@pam/token/kopsrox`
Expand Down
4 changes: 4 additions & 0 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ documentation is a WIP :construction:
- [etcd](#etcd)
- [node](#node)
- [k3s](#k3s)
- [kubevip](#kubevip)

## :cyclone: image <a name=image>
### :white_check_mark: create
Expand Down Expand Up @@ -119,4 +120,7 @@ usage:
- uninstalls k3s using the usual script
- for experimenting with k3s reinstall

## :cyclone: kubevip <a name=kubevip>

### reinstall
- reinstalls kubevip
2 changes: 1 addition & 1 deletion lib/kopsrox_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def vm_info(vmid,node=node):

except:
# no image found
kmsg(kname, 'no template detected - please run "kopsrox image create"', 'err')
kmsg(kname, f'{cluster_name} image not found - please run "kopsrox image create"', 'err')
exit(0)

# get image info
Expand Down
4 changes: 2 additions & 2 deletions lib/kopsrox_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def init_kopsrox_ini():
config.add_section('kopsrox')

# upstream image
config.set('kopsrox', '; the upstream cloud image used to create the kopsrox template')
config.set('kopsrox', 'cloud_image_url', 'https://cloud-images.ubuntu.com/minimal/daily/mantic/current/mantic-minimal-cloudimg-amd64.img')
config.set('kopsrox', '; the upstream cloud image used to create the kopsrox image')
config.set('kopsrox', 'cloud_image_url', '//cloud-images.ubuntu.com/minimal/daily/oracular/current/oracular-minimal-cloudimg-amd64.img')

# disk size for kopsrox vms
config.set('kopsrox', '; size of kopsrox vm disk in Gib ')
Expand Down
23 changes: 11 additions & 12 deletions lib/verb_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@

# create image
if cmd == 'create':
kmsg(f'{kname}create', f'name:{cluster_name}-i1', 'sys')

# get image name from url
cloud_image = cloud_image_url.split('/')[-1]
kmsg(f'{kname}download', f'{cloud_image_url}')
kmsg(f'{kname}create', f'{cloud_image}-{k3s_version} {storage}/{cluster_name}-i0/{cluster_id}', 'sys')

# check if image already exists
if os.path.isfile(cloud_image):
kmsg(kname, f'{cloud_image} already exists', 'err')
kmsg(f'{kname}check', f'Error! {cloud_image} already exists - please delete', 'err')
exit(0)

# check img can be downloaded
try:
kmsg(f'{kname}wget', f'{cloud_image_url}')
wget.download(cloud_image_url)
print()
except:
kmsg(kname, f'unable to download {cloud_image_url}', 'err')
kmsg(f'{kname}check', f'unable to download {cloud_image_url}', 'err')
exit(0)

# script to install disable selinux on Rocky
Expand All @@ -59,10 +59,10 @@
cp /dev/null /etc/sysconfig/qemu-ga
fi'''
# shouldn't really need root but run into permissions problems
patch_cmd = f'sudo virt-customize --smp 2 -m 2048 -a {cloud_image} --install qemu-guest-agent --run-command "{virtc_script}"'
virtc_cmd = f'sudo virt-customize --smp 2 -m 2048 -a {cloud_image} --install qemu-guest-agent --run-command "{virtc_script}"'

kmsg('image_virt-customize', 'configuring image')
patch_out = local_os_process(patch_cmd)
kmsg(f'{kname}virt-customize', 'configuring image')
local_os_process(virtc_cmd)

# destroy template if it exists
try:
Expand All @@ -88,32 +88,31 @@
agent = ('enabled=true'),
hotplug = 0,
ciupgrade = 0,
description = f'<pre>{cluster_name} template\n{cloud_image}\n{k3s_version}',
description = f'<pre>{cluster_name} image\nbased on: {cloud_image}\nk3s version: {k3s_version}',
ciuser = cloudinituser,
cipassword = cloudinitpass,
sshkeys = cloudinitsshkey,
tdf = '1',
))

# shell to import disk
# import-from requires the full path os.getcwd required here
import_cmd = f'''
sudo qm set {cluster_id} --scsi0 {storage}:0,import-from={os.getcwd()}/{cloud_image},iothread=true,aio=native,discard=on,ssd=1
sudo qm set {cluster_id} --scsi0 {storage}:0,import-from={os.getcwd()}/{cloud_image},iothread=true,aio=native
mv {cloud_image} {cloud_image}.patched'''

# run shell command to import
kmsg(f'image_qm-import', f'{cloud_image} > {storage}/{cluster_id}')
local_os_process(import_cmd)

# convert to template via create base disk also vm config
task_status(prox.nodes(node).qemu(cluster_id).template.post())
task_status(prox.nodes(node).qemu(cluster_id).config.post(template = 1))
kmsg(f'{kname}qm-import', f'done')

# image info
if cmd == 'info':
image_info()

# destroy image
if cmd == 'destroy':
kmsg(kname, f'{kopsrox_img()}/{cloud_image_desc}', 'warn')
kmsg(f'{kname}destroy', f'{kopsrox_img()}/{cloud_image_desc}', 'warn')
prox_destroy(cluster_id)

0 comments on commit fb71c10

Please sign in to comment.