You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Install kubectl
curl -LO "https://dl.k8s.io/release/v1.32.2/bin/linux/amd64/kubectl"
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# Enable bash completionecho'source <(kubectl completion bash)'>>~/.bashrc
# Create an alias for kubectl (k is easier to type than kubectl)echo'alias k=kubectl'>>~/.bashrc
echo'complete -o default -F __start_kubectl k'>>~/.bashrc
# Load the new configurationsource~/.bashrc
curl -fsSL https://get.docker.com | sh
apt install jq unzip -y
# Download the Helm installation script and make it executable
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
# Run the installation script and remove it after installation
./get_helm.sh
rm get_helm.sh
# Download Terraform archive
curl https://releases.hashicorp.com/terraform/1.11.1/terraform_1.11.1_linux_amd64.zip -o terraform.zip
# Unzip the archive
unzip terraform.zip
# Move the binary to /usr/local/bin
mv terraform /usr/local/bin
# Remove the archive
rm terraform.zip
cat <<EOF > $HOME/RestQR/deploy/terraform/main.tfterraform { required_providers { digitalocean = { source = "digitalocean/digitalocean" version = "~> 2.0" } }}provider "digitalocean" { token = var.do_token}resource "digitalocean_kubernetes_cluster" "myclusters" { for_each = { for name in var.names : name => name } name = each.value region = var.region version = var.k8s_version node_pool { name = "default" size = var.node_size node_count = var.node_count auto_scale = true min_nodes = 1 max_nodes = 3 }}output "kubeconfigs" { description = "Kubeconfig files for the Kubernetes clusters" value = { for name, cluster in digitalocean_kubernetes_cluster.myclusters : name => cluster.kube_config[0].raw_config } sensitive = true}EOF
# Go to your DigitalOcean account # and create a new Personal Access Token # if it's not already created.export DIGITALOCEAN_TOKEN="<YOUR_DIGITALOCEAN_TOKEN>"# The name of the cluster# Keep it simple and lowercaseexport CLUSTER_NAME="restqr"# The version of Kubernetes# Versions slugs may change, check the available versions on do-api.devexport K8S_VERSION="1.30.10-do.0"# Choose the region where you want to create the clusterexport REGION="fra1"# The number of nodes in the clusterexport NODE_SIZE="s-2vcpu-4gb"# The size of the nodes.# You may want to increase the size later depending on the workload.export NODE_COUNT=1
# This file contains sensitive information# and **should be ignored by git**
cat <<EOF > $HOME/RestQR/deploy/terraform/variables.tfvariable "do_token" { description = "DigitalOcean API Token" type = string sensitive = true default = "$DIGITALOCEAN_TOKEN"}variable "names" { description = "List of Kubernetes cluster names" type = list(string) default = [ "$CLUSTER_NAME" ]}variable "region" { description = "Region for the Kubernetes clusters" type = string default = "$REGION"}variable "k8s_version" { description = "Kubernetes version for the cluster" type = string default = "$K8S_VERSION"}variable "node_size" { description = "Size of the Kubernetes nodes" type = string default = "$NODE_SIZE"}variable "node_count" { description = "Number of nodes per cluster" type = number default = $NODE_COUNT}EOF
cd$HOME/RestQR/deploy/terraform
terraform init
terraform plan -out=tfplan.binary
terraform apply tfplan.binary
# Create the kubeconfig directory
mkdir -p $HOME/.kube
# Get the kubeconfig file# CLUSTER_NAME is a variable that we exported earlier# Verify it by running `echo $CLUSTER_NAME`
terraform output -json kubeconfigs | \
jq -r ".\"$CLUSTER_NAME\""> \
$HOME/.kube/config
# Verify the connection
kubectl get nodes