Skip to content

Simple example to deploy nodes for a Kubernetes cluster on Openstack using Pulumi

License

Notifications You must be signed in to change notification settings

qjoly/pulumi-kubernetes-openstack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Helm LOGO

Blog Pulumi Kubernetes Openstack

Pulumi Kubernetes Openstack Example

This example demonstrates how to deploy nodes for a Kubernetes cluster on Openstack using Pulumi.

Note: By default, the values in the Pulumi.yaml use Infomaniak Openstack. You can change the values in the Pulumi.yaml file to match your Openstack configuration.

Prerequisites

  1. Install Pulumi
  2. Install Python3
  3. Create a virtual environment:
python3 -m venv venv
  1. Install the required Python packages:
python3 -m pip install -r requirements.txt

Running the Example

Login to your openstack account (horizon) and source the openstack rc file:

source openstack.rc

Create a new project using this template:

pulumi new https://github.com/qjoly/pulumi-kubernetes-openstack/tree/main

Run the pulumi program:

pulumi up

Install Kubernetes cluster

Export the private key that can be used to connect to the nodes:

pulumi stack output nodes_keypair --show-secrets > nodes_keypair.pem

Send it to the admin node:

scp nodes_keypair.pem debian@$(pulumi stack output admin_external_ip):.ssh/id_rsa
ssh debian@$(pulumi stack output admin_external_ip) chmod 600 .ssh/id_rsa

⚠️ Note that you have to set the pulumi config passphrase to access content of the private key.

Generate the inventory file:

pulumi stack output ip_addresses --json | python3 generate_inventory.py > inventory.ini
scp inventory.ini debian@$(pulumi stack output admin_external_ip):./inventory.ini

On the admin node, Create a virtual environment and install the required packages:

ssh debian@$(pulumi stack output admin_external_ip)
git clone https://github.com/kubernetes-sigs/kubespray && cd kubespray
cp -r inventory/sample/ ./inventory/pulumi-cluster
cp ~/inventory.ini ./inventory/pulumi-cluster/inventory.ini
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
ansible-playbook -i ./inventory/pulumi-cluster/inventory.ini -u debian --become --become-user=root cluster.yml
All in one script

⚠️ Only run this script if you are sure of what you are doing. ⚠️

pulumi stack output nodes_keypair --show-secrets > nodes_keypair.pem
scp nodes_keypair.pem debian@$(pulumi stack output admin_external_ip):.ssh/id_rsa
ssh debian@$(pulumi stack output admin_external_ip) chmod 600 .ssh/id_rsa
pulumi stack output ip_addresses --json | python3 generate_inventory.py > inventory.ini
scp inventory.ini debian@$(pulumi stack output admin_external_ip):./inventory.ini
ssh debian@$(pulumi stack output admin_external_ip) \ '
  git clone https://github.com/kubernetes-sigs/kubespray && cd kubespray && \
  cp -r inventory/sample/ ./inventory/pulumi-cluster && \
  cp ~/inventory.ini ./inventory/pulumi-cluster/inventory.ini && \
  python3 -m venv venv && \
  source venv/bin/activate && \
  pip install -r requirements.txt && \
  ansible-playbook -i ./inventory/pulumi-cluster/inventory.ini -u debian --become --become-user=root cluster.yml'

CP_IP=$(pulumi stack output 'ip_addresses' | jq -r '."kube-controlplane"[0]')
ssh debian@$(pulumi stack output admin_external_ip) "ssh-keyscan -H $CP_IP >> ~/.ssh/known_hosts && mkdir -p .kube && ssh $CP_IP sudo cat /root/.kube/config > .kube/config && sed -i 's/127.0.0.1/$CP_IP/g' ~/.kube/config && chmod 600 .kube/config && echo 'Done'"

Output of the Pulumi program

⚠️ Note that the output of the pulumi program will be different as the resources are created dynamically.

Destroy the resources

To destroy the resources created by the Pulumi program, run the following command:

pulumi destroy

About

Simple example to deploy nodes for a Kubernetes cluster on Openstack using Pulumi

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages