capmox install

https://github.com/ionos-cloud/cluster-api-provider-proxmox/blob/main/docs/Usage.md#check-the-status-of-the-cluster

Step 1: Update Your System

First, ensure your system is updated:

sudo apt-get update
sudo apt-get upgrade

Step 2: Install Docker

CAPMox requires Docker to manage Kubernetes clusters. Install Docker as follows:

# Install prerequisite packages
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Add Docker's official APT repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# Install Docker
sudo apt-get update
sudo apt-get install docker-ce

# Verify Docker installation
sudo systemctl status docker

Add your user to the docker group to run Docker without sudo:

sudo usermod -aG docker $USER

After running the above command, log out and log back in to apply the group changes.

Step 3: Install kubelet kubeadm kubectl

Install kubectl, the Kubernetes command-line tool:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Step 4: Install kind

kind (Kubernetes in Docker) is required to run Kubernetes clusters locally. Install kind using the following commands:

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

Step 5: Download and Install the Latest Go

CAPMox requires Go for building the binaries. Install Go as follows:

wget https://go.dev/dl/go1.23.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.23.0.linux-amd64.tar.gz

echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile
source ~/.profile

Verify the installation:

go version

Step 6: Install clusterctl

clusterctl is the Cluster API CLI tool. To install it:

# Download the latest release of clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.8.2/clusterctl-linux-amd64 -o clusterctl

Install clusterctl:
sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl

# Verify installation
clusterctl version

Enabling feature gates:

Feature gates can be enabled by exporting environment variables before executing clusterctl init. For example, the ClusterTopology feature, which is required to enable support for managed topologies and ClusterClass, can be enabled via:

export CLUSTER_TOPOLOGY=true

Step 7: Install make

sudo apt-get install make

Step 8: Clone the CAPMox Repository

# Now that all dependencies are installed, clone the CAPMox repository:
git clone https://github.com/ionos-cloud/cluster-api-provider-proxmox.git
cd cluster-api-provider-proxmox

Step 9: Build CAPMox

Build CAPMox using the following command:

make build

This will compile the necessary binaries for CAPMox.

Step 10: Create a Kind cluster:

Configure the cluster with a custom configuration file that binds ports from the Docker container to the host’s network. This allows access to the cluster’s API server from the host’s IP address.

vi kind-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    extraPortMappings:
      - containerPort: 6443  # Kubernetes API server port
        hostPort: 6443       # Map to host's port 6443
        listenAddress: "0.0.0.0"  # Listen on all host interfaces
        protocol: TCP
    kubeadmConfigPatches:
      - |
        apiVersion: kubeadm.k8s.io/v1beta2
        kind: ClusterConfiguration
        apiServer:
          certSANs:
            - "127.0.0.1"
            - "localhost"
            - "192.168.57.130"  # Host IP
kind create cluster --name capmox-mgmt --config kind-config.yaml
kubectl config set-cluster kind-capmox-mgmt --insecure-skip-tls-verify=true

kubectl get nodes

kubectl config use-context kind-capmox-mgmt

Step 10: Initialize Cluster API

Initialize the Cluster API components:

clusterctl init --core cluster-api --bootstrap kubeadm --control-plane kubeadm

Step 11: Initialize the management cluster for Proxmox infrastructure

# The host for the Proxmox cluster
export PROXMOX_URL="https://pve.example:8006"
# The Proxmox token ID to access the remote Proxmox endpoint
export PROXMOX_TOKEN='root@pam!capi'
# The secret associated with the token ID
# You may want to set this in `$XDG_CONFIG_HOME/cluster-api/clusterctl.yaml` so your password is not in
# bash history
export PROXMOX_SECRET="1234-1234-1234-1234"


# Finally, initialize the management cluster
clusterctl init --infrastructure proxmox --ipam in-cluster
kubectl config view --minify --flatten --context kind-capmox-mgmt > capmox-mgmt-kubeconfig
kubectl create secret generic kind-capmox-mgmt-kubeconfig --from-file=value=capmox-mgmt-kubeconfig -n default
clusterctl get kubeconfig kind-capmox-mgmt

Step 12: Configure Proxmox Credentials

Set up Proxmox credentials:

  1. Create Proxmox user and edit clusterctl configuration file:
pveum user add capmoxuser@pve
pveum aclmod / -user capmoxuser@pve -role PVEVMAdmin
pveum user token add capmoxuser@pve capi -privsep 0  

pveum aclmod / -user capmoxuser@pve -role Administrator

Step 13: Create a Kubernetes Cluster

A ClusterAPI compatible image must be available in your Proxmox cluster. For instructions on how to build a compatible VM template see image-builder.

# The node that hosts the VM template to be used to provision VMs
export PROXMOX_SOURCENODE="pve"
# The template VM ID used for cloning VMs
export TEMPLATE_VMID=100
# The boot volume
export BOOT_VOLUME_DEVICE= "scsi0"
# The ssh authorized keys used to ssh to the machines.
export VM_SSH_KEYS="ssh-ed25519 ..., ssh-ed25519 ..."
# The IP address used for the control plane endpoint
export CONTROL_PLANE_ENDPOINT_IP=10.10.10.4
# The IP ranges for Cluster nodes
export NODE_IP_RANGES="[10.10.10.5-10.10.10.50, 10.10.10.55-10.10.10.70]"
# The gateway for the machines network-config.
export GATEWAY="10.10.10.1"
# Subnet Mask in CIDR notation for your node IP ranges
export IP_PREFIX=24
# The Proxmox network device for VMs
export BRIDGE="vmbr1"
# The dns nameservers for the machines network-config.
export DNS_SERVERS="[8.8.8.8,8.8.4.4]"
# The Proxmox nodes used for VM deployments
export ALLOWED_NODES="[pve1,pve2,pve3]"

Generate and apply a configuration to create a new Kubernetes cluster:

clusterctl generate cluster capi-quickstart \
  --kubernetes-version v1.31.0 \
  --control-plane-machine-count=1 \
  --worker-machine-count=2 \
  > capi-quickstart.yaml

kubectl apply -f capi-quickstart.yaml

Step 14: Verify and Access the Cluster

Verify the cluster creation:

kubectl get clusters

Access the cluster:

kubectl config use-context my-cluster

Conclusion

You now have a fully functional installation of CAPMox on a clean Ubuntu system with all necessary dependencies. This setup allows you to manage Kubernetes clusters on a Proxmox environment. For further configurations and detailed usage, refer to the CAPMox documentation.