This repository contains code for creating a Kubernetes cluster and running a minimal Linux (Alpine) container in it.
.
├── README.md # Usage instructions
├── terraform/ # Code for creating Kubernetes cluster
│ ├── main.tf # Main Terraform configuration file
│ ├── variables.tf # Configuration variables
│ └── outputs.tf # Output values for use after deployment
├── kubernetes/ # Kubernetes manifests
│ └── mini-linux-deployment.yaml # Manifest for running a mini-Linux container
└── docker/ # Files for building container image
└── Dockerfile # Definition of mini-Linux image
-
Navigate to the
terraformdirectory:cd terraform -
Initialize Terraform:
terraform init
-
Configure variables in the
terraform.tfvarsfile or use environment variables. -
Create an execution plan:
terraform plan -out=plan
-
Apply the configuration:
terraform apply plan
-
After completion, get the configuration for accessing the cluster:
terraform output kubeconfig > ~/.kube/config
-
Navigate to the
dockerdirectory:cd ../docker -
Build the Docker image:
docker build -t mini-linux:latest . -
Push the image to a registry (e.g., Docker Hub):
docker tag mini-linux:latest yourusername/mini-linux:latest docker push yourusername/mini-linux:latest
-
Navigate to the
kubernetesdirectory:cd ../kubernetes -
Open the
mini-linux-deployment.yamlfile and update the image reference if necessary. -
Apply the manifest to create the deployment:
kubectl apply -f mini-linux-deployment.yaml
-
Check the deployment status:
kubectl get pods
The repository supports three major cloud providers. To select a provider, set the cloud_provider variable in the terraform.tfvars file.
To access the mini-Linux container console, use:
kubectl exec -it $(kubectl get pod -l app=mini-linux -o jsonpath="{.items[0].metadata.name}") -- /bin/sh