Creating a Hybrid OpenShift/OKD Clusters using Terraform, Ansible, and Cloud-init on Proxmox
In this article, we will discuss the steps to create a hybrid OpenShift/OKD clusters using Terraform, Ansible, and Cloud-init on Proxmox. We will also cover the key concepts, subtopics, and provide detailed explanations for each step.
Prerequisites
- Proxmox server with a minimum of two VMs
- Terraform installed on the host machine
- Ansible installed on the host machine
- Access to the Proxmox API
- A working knowledge of Terraform, Ansible, and Cloud-init
Steps
- Create Terraform Proxmox VM Resource
First, we will create Terraform resources to manage Proxmox VMs. In the terraform.tf file, define the Proxmox server, VMs, and their resources.
provider "proxmox" {
pm_api_version = "1.0"
pm_tls_ca_pem_file = "ca.crt"
pm_tls_cert_pem_file = "cert.pem"
pm_tls_key_pem_file = "key.pem"
}
variable "proxmox_host" {
description = "Proxmox server IP address"
type = string
default = "192.168.1.10"
}
variable "proxmox_user" {
description = "Proxmox API user"
type = string
default = "root"
}
variable "proxmox_password" {
description = "Proxmox API password"
type = string
sensitive = true
}
variable "node_count" {
description = "Number of nodes in the OpenShift/OKD cluster"
type = number
default = 3
}
resource "proxmox_vm" "node" {
count = var.node_count
name = "node-${count.index + 1}"
target_node = var.proxmox_host
clone = "template-centos8"
cores = 2
sockets = 1
memory = 4096
networks = ["vmbr1"]
start_on_node = var.proxmox_host
agent5_template = "template-cloud-init"
agent5_user = "root"
agent5_password = var.proxmox_password
disk {
type = "scsi"
size = "10GB"
}
cspe_enabled = true
}
- Create Ansible Playbook for OpenShift/OKD Cluster Installation
Next, create an Ansible playbook to install OpenShift/OKD and its dependencies on the Proxmox VMs. In the playbook.yml file, define the tasks to install and configure OpenShift/OKD.
- hosts: all
vars:
openshift_version: "4.9"
tasks:
- name: Install Docker
yum:
name: docker
state: present
- name: Install Kubernetes
yum:
name: kubernetes-{{ openshift_version }}-x86_64
state: present
- name: Start and enable Kubernetes
systemd:
name: kubelet
enabled: yes
daemon_reload: yes
state: started
- name: Install OpenShift/OKD
yum:
name: openshift-{{ openshift_version }}-client
state: present
- name: Configure OpenShift/OKD
command: openshift-install create cluster --dir=/tmp/openshift-cluster --log-level=debug
- Create Cloud-init Configuration
Create a cloud-init configuration script to install and run Ansible on the Proxmox VMs. Save the following content in the user-data file.
#!/bin/bash
# Install Ansible
yum install -y epel-release ansible
# Install Python3
yum install -y python3 python3-pip
# Install Python3 Ansible plugin
pip3 install ansible
# Download and run the Ansible playbook
ansible-playbook playbook.yml
- Terraform Application
Run the Terraform application to create the Proxmox VMs and apply the cloud-init configuration.
terraform init
terraform apply
- Monitor Proxmox VMs
After the Terraform application finishes, log in to the Proxmox web interface and monitor the status of the VMs. Once the VMs are up and running, SSH into them and verify that OpenShift/OKD is installed and running.
References
- Proxmox API documentation: https://pve.proxmox.com/wiki/API_3_0
- OpenShift/OKD documentation: https://docs.openshift.com/
- Ansible documentation: https://docs.ansible.com/
- Cloud-init documentation: https://cloudinit.readthedocs.io/
Code Blocks
provider "proxmox" {
...
}
resource "proxmox_vm" "node" {
...
}
- hosts: all
vars:
...
tasks:
...
#!/bin/bash
...