Giter VIP home page Giter VIP logo

k8-cluster-in-proxmox's Introduction

Deploy a K8 cluster in Proxmox using Terraform and Ansible

Running a kube cluster in any public cloud provider is a costly business. There are many ways to deploy a local cluster with virtualbox, kind etc. However I wanted to use Proxmox with my home server and I could not find any complete example of deploying a fully automated cluster using Terraform and Ansible. So I created this repo. This is not production grade at all but perfect for running a 3 node cluster at home.

Pre-requisits

  • Create a user with API token in Proxmox following this guide https://registry.terraform.io/providers/Telmate/proxmox/latest/docs
  • Make sure NOT to enable privilege separation for the API key. Otherwise Terraform will not be able to find the VM template.
  • VM template (follow steps below to create a template)
  • CIDR range to setup static IPs for the cluster nodes. Below are the default IPs.
master  192.168.193.20
worker0 192.168.193.30
worker1 192.168.193.31
  • Terraform and Ansible

How to use this code

  • Make sure you have all the pre-requisites
  • Clone this repo
  • Export PM_API_TOKEN_ID and PM_API_TOKEN_SECRET
  • Run Terraform init from the root folder
  • Run Terraform apply
  • SSH into nodes as needed with user jay

Notes

  • Make sure to install a CNI plugin. Cilium and WeaveNet are some of the options.
  • If you want to change the CIDR range/username etc, you may have to dig a little bit. I will update this documentation to make it easier at some point.
  • Check the locations of the SSH keys, I used the usual default locations and file names ( ~/.ssh/id_rsa )
  • Use MetalLB https://metallb.universe.tf/installation/ to play with Ingress and Ingress Controller.
  • Use https://github.com/kubernetes-sigs/metrics-server metrics server, but make sure to update the deployment with --kubelet-insecure-tls arg to get it running.

How to create a VM template in Proxmox

# download the cloud image
cd /var/lib/vz/template/iso
# latest LTS version
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img

# create a new VM
qm create 100 --name "ubuntu-2204-jammy-cloudinit-template" --memory 4096 --cores 2 --net0 virtio,bridge=vmbr0

# import the downloaded disk to local-lvm storage
qm importdisk 100 jammy-server-cloudimg-amd64.img local-lvm

# finally attach the new disk to the VM as scsi drive
qm set 100 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-100-disk-0

# configure a CD-ROM drive, which will be used to pass the Cloud-Init data to the VM
qm set 100 --ide2 local-lvm:cloudinit

# to be able to boot directly from the Cloud-Init image, set the bootdisk parameter to scsi0
qm set 100 --boot c --bootdisk scsi0

# configure a serial console and use it as a display
qm set 100 --serial0 socket --vga serial0

# enable the agent
qm set 100 --agent=1

# convert the VM into a template
qm template 100

Reference:

https://pve.proxmox.com/pve-docs/chapter-qm.html#_preparing_cloud_init_templates

k8-cluster-in-proxmox's People

Contributors

jay-flood avatar jayanath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

k8-cluster-in-proxmox's Issues

Ansible locking issue

Ansible fails with following error.
Could not get lock /var/lib/apt/lists/lock. It is held by process 1235 (apt-get)
This is a known issue and I need to refactor the playbook bit more to fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.