Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions kind_ec2_installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Kind K8s Installation Guide for AWS EC2
<img src="https://github.com/user-attachments/assets/2942ee8e-7e11-4f58-a1de-bc939a33b8ab" alt="kind logo" style="height: 50px; width: auto;">
<img src="https://github.com/user-attachments/assets/2af10983-a2f4-492a-961c-28b6f36f977a" alt="k8s logo" style="height: 50px; width: auto;">
<img src="https://github.com/user-attachments/assets/9f1b82ea-d285-43ed-b7de-564019075ab1" alt="docker logo" style="height: 50px; width: auto;">
<img src="https://github.com/user-attachments/assets/51fea0a8-3a8c-4727-8129-784c35f1389c" alt="ec2 logo" style="height: 50px; width: auto;">
Comment on lines +2 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using permanent image URLs

The current image URLs use temporary paths (user-attachments). Consider:

  1. Moving images to a permanent location in the repository (e.g., docs/images/)
  2. Using relative paths to reference them
-<img src="https://github.com/user-attachments/assets/2942ee8e-7e11-4f58-a1de-bc939a33b8ab" alt="kind logo" style="height: 50px; width: auto;">
+<img src="docs/images/kind-logo.png" alt="kind logo" style="height: 50px; width: auto;">

Committable suggestion skipped: line range outside the PR's diff.


This guide provides step-by-step instructions for installing Kind K8s on AWS EC2 (Ubuntu). Kind allows you to run a single-node Kubernetes cluster locally for development and testing purposes.

> ⚠️ **Caution:**
> This installation guide recommends using a `t2.medium` EC2 instance, which is **NOT** covered under the AWS Free Tier.
> Please be aware that using this instance type may incur **ADDITIONAL CHARGES**. For optimal performance with Kind K8s, it is advised to use a higher-tier EC2 instance to meet the computational requirements and **not** `t2.micro`.


## Pre-requisites
* AWS EC2 (Ubuntu)
* Docker
* kubectl

Comment on lines +14 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Expand prerequisites section

Add essential prerequisites for a complete setup:

  • Minimum storage requirements
  • Required open ports in security group
  • SSH key pair for EC2 access
  • IAM permissions needed
 ## Pre-requisites
 * AWS EC2 (Ubuntu)
+* AWS Account with appropriate IAM permissions
+* SSH key pair for EC2 access
+* Security Group with following ports open:
+  * SSH (22)
+  * Container ports (30000-32767) for NodePort services
 * Docker
 * kubectl
+* Minimum 15GB storage
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Pre-requisites
* AWS EC2 (Ubuntu)
* Docker
* kubectl
## Pre-requisites
* AWS EC2 (Ubuntu)
* AWS Account with appropriate IAM permissions
* SSH key pair for EC2 access
* Security Group with following ports open:
* SSH (22)
* Container ports (30000-32767) for NodePort services
* Docker
* kubectl
* Minimum 15GB storage

## Pre-requisites Installation
### 1. Create an EC2 (Ubuntu) and connect to it
* Create an EC2 of Instance type `t2.medium` and storage size of `15 GB` or more
* Launch the newly created EC2 and connect to it

### 2. Update system packages
Update your package lists to make sure you are getting the latest version and dependencies.

```bash
sudo apt update
```

![update-sys-package](https://github.com/user-attachments/assets/64a4d6f2-8039-4bf8-ab6d-eeab1c8b8e5b)

### 3. Install Docker

Since **kind** runs Kubernetes clusters using Docker containers as nodes, Docker needs to be installed.

* Install Docker using the below command
```bash
sudo apt install docker.io -y
```

![install-docker](https://github.com/user-attachments/assets/8abdd518-ba2a-479d-b898-3c2eacd256e6)

Docker service will be started and enabled by default. Verify if its started and enabled using `sudo systemctl status docker`

![systemctl-status-docker](https://github.com/user-attachments/assets/31526fcb-cbe2-4f95-9b3b-e520f9e12d81)

* If Docker service is not started or enabled, do it using the command below
```bash
sudo systemctl enable --now docker
```

* Add current user to docker group (To use docker without root)

```bash
sudo usermod -aG docker $USER && newgrp docker
```
* Verify using `docker --version`

![docker-version](https://github.com/user-attachments/assets/f9fe3f02-4178-4102-a088-0edec30494ac)

Comment on lines +33 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance Docker installation security

Consider adding security best practices and version pinning:

  • Pin Docker version for reproducibility
  • Add post-installation security steps
  • Include Docker daemon configuration
 ### 3. Install Docker
+
+It's recommended to install a specific version of Docker for reproducibility:
+
+```bash
+DOCKER_VERSION="24.0.7"
+sudo apt install docker.io=${DOCKER_VERSION}* -y
+```
+
+Configure Docker daemon with security best practices:
+
+```bash
+sudo tee /etc/docker/daemon.json <<EOF
+{
+  "log-driver": "json-file",
+  "log-opts": {
+    "max-size": "100m"
+  },
+  "default-ulimits": {
+    "nofile": {
+      "Name": "nofile",
+      "Hard": 64000,
+      "Soft": 64000
+    }
+  }
+}
+EOF
+
+sudo systemctl restart docker
+```


### 4. Install kubectl

Download **kubectl**, which is a Kubernetes command-line tool.

* Download kubectl binary with curl on Linux
```bash
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
```

> **Optional**: **Validate the downloaded kubectl binary **
> * Download the kubectl checksum file
> `curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"`
> * Validate the kubectl binary against the checksum file
> `echo "$(cat kubectl.sha256) kubectl" | sha256sum --check`
> * If valid, the output is `kubectl: OK`

Comment on lines +72 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Make checksum verification mandatory

The checksum verification step should not be optional as it ensures the integrity and authenticity of the kubectl binary.

-Optional**: **Validate the downloaded kubectl binary  **
-> * Download the kubectl checksum file  
-> `curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"`  
-> * Validate the kubectl binary against the checksum file  
-> `echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check`  
-> * If valid, the output is `kubectl: OK`
+**Important**: Verify kubectl binary integrity
+
+```bash
+# Download kubectl checksum file
+curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
+
+# Validate kubectl binary (Required)
+echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
+
+# Proceed only if verification succeeds with "kubectl: OK"
+```
🧰 Tools
🪛 Markdownlint

72-72: null
Spaces inside emphasis markers

(MD037, no-space-in-emphasis)

* Install kubectl
```bash
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
```

* Verify installation by checking kubectl version
```bash
kubectl version --client
```

![kubectl-all](https://github.com/user-attachments/assets/a5808228-1ac0-4f6d-b3a1-b68417556c91)

Comment on lines +63 to +90
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Specify kubectl version compatibility

Add a note about kubectl version compatibility with Kind. The kubectl version should be within one minor version of the Kind cluster's Kubernetes version.

🧰 Tools
🪛 Markdownlint

72-72: null
Spaces inside emphasis markers

(MD037, no-space-in-emphasis)

## Kind K8s Installation
### Install Kind
Download and install **kind** k8s
* Download kind binary with curl on Linux
```bash
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve version handling and architecture support

  1. Consider using a version variable instead of hardcoding:
-[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
+KIND_VERSION=$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | grep tag_name | cut -d '"' -f 4)
+if [ $(uname -m) = x86_64 ]; then
+  curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64
+elif [ $(uname -m) = aarch64 ]; then
+  curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-arm64
+else
+  echo "Unsupported architecture"
+  exit 1
+fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
KIND_VERSION=$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | grep tag_name | cut -d '"' -f 4)
if [ $(uname -m) = x86_64 ]; then
curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64
elif [ $(uname -m) = aarch64 ]; then
curl -Lo ./kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-arm64
else
echo "Unsupported architecture"
exit 1
fi

```
* Install kind
```bash
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
```
* Run `kind` to verify if its installed

![kind-all](https://github.com/user-attachments/assets/83f53246-a60e-49dc-a4a7-e8418354e9bb)

Comment on lines +91 to +106
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add support for ARM64 architecture

AWS offers Graviton (ARM64) instances which can be more cost-effective. Add support for ARM64 architecture.

 Download and install **kind** k8s
 * Download kind binary with curl on Linux
   ```bash
-  [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
+  ARCH=$(uname -m)
+  case $ARCH in
+    x86_64)
+      curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
+      ;;
+    aarch64)
+      curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-arm64
+      ;;
+    *)
+      echo "Unsupported architecture: $ARCH"
+      exit 1
+      ;;
+  esac

<!-- This is an auto-generated comment by CodeRabbit -->

## Kind K8s Usage
### Create a Cluster
Create a Kubernetes Cluster using `kind create cluster`. Use the `--name` flag to provide a cluster name. For Example, `kind create cluster --name=<cluster-name>` (Replace `<cluster-name>` with desired cluster name).

![kind-create-cluster](https://github.com/user-attachments/assets/173f4a67-000c-497c-a878-0b2da85e2736)

### Interacting with Clusters
`kubectl` can be used to interact with created clusters.

* To list all the clusters, execute `kind get clusters`

![kind-get-clusters](https://github.com/user-attachments/assets/0514244b-0517-402a-86e1-0712c08c8bae)

* To get nodes, run `kubectl get nodes`

![kind node](https://github.com/user-attachments/assets/9a035322-a85f-4a98-8716-6dff777a20a5)

### Optional: Delete cluster
Delete a Kubernetes Cluster using `kind delete cluster`. Use the `--name` flag to provide a cluster name. For Example, `kind delete cluster --name=<cluster-name>` (Replace `<cluster-name>` with desired cluster name).

![kind delete cluster](https://github.com/user-attachments/assets/766629d4-6b99-4ab9-a33f-f3e63e0e7916)


Comment on lines +107 to +129
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Expand cluster management section

Add essential cluster management topics:

  • Cluster configuration using YAML
  • Multi-node cluster setup
  • Resource limits configuration
  • Persistent storage setup
  • Ingress configuration
  • Common troubleshooting steps
 ## Kind K8s Usage
+
+### Cluster Configuration
+Create a config file `kind-config.yaml`:
+```yaml
+kind: Cluster
+apiVersion: kind.x-k8s.io/v1alpha4
+nodes:
+- role: control-plane
+  extraPortMappings:
+  - containerPort: 80
+    hostPort: 80
+- role: worker
+- role: worker
+```
+
+Create cluster with config:
+```bash
+kind create cluster --config kind-config.yaml
+```
+
+### Storage Setup
+Apply local storage class:
+```bash
+kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
+```
+
+### Troubleshooting
+Common issues and solutions:
+- Check logs: `kubectl logs -n kube-system kube-controller-manager-kind-control-plane`
+- Check events: `kubectl get events --all-namespaces`
+- Resource constraints: `kubectl describe node`