> ## Documentation Index
> Fetch the complete documentation index at: https://docs.briankimemia.is-a.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubanetes2

# Launching Kubernetes on AWS (EKS)

## Prerequisites

<Note>
  ⚙️ **Ensure your environment is ready!**
  Before setting up Amazon EKS, confirm that you have the following:

  * **AWS Account** with appropriate permissions.
  * **AWS CLI** installed and configured.
  * **kubectl** installed.
  * **eksctl** installed.
</Note>

## Setting up Amazon EKS

### 1. Install Required Tools

```bash theme={null}
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
 
# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin 
 
# Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" 
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
```

<Tip>
  💡 **Why install these tools?**
  AWS CLI helps manage AWS resources, kubectl is for Kubernetes management, and eksctl simplifies EKS cluster setup.
</Tip>

### 2. Create an EKS Cluster

```bash theme={null}
eksctl create cluster \
    --name my-eks-cluster \
    --region us-west-2 \
    --node-type t3.medium \
    --nodes 2 \
    --nodes-min 1 \
    --nodes-max 3 \
    --managed
```

<Warning>
  ⚠️ **Resource Costs**
  Remember that running a cluster incurs AWS charges. Be sure to monitor your usage to avoid unexpected bills.
</Warning>

### 3. Configure kubectl

```bash theme={null}
aws eks update-kubeconfig --name my-eks-cluster --region us-west-2
```

<Note>
  🛠️ **Validate Configuration**
  Run `kubectl get nodes` to confirm your cluster is successfully set up.
</Note>

## Cluster Management

### Scaling the Cluster

```bash theme={null}
# Scale the node group
eksctl scale nodegroup --cluster=my-eks-cluster --name=ng-1 --nodes=3

# Auto-scaling configuration
eksctl create nodegroup \
    --cluster my-eks-cluster \
    --region us-west-2 \
    --name ng-mixed \
    --node-type t3.medium \
    --nodes 2 \
    --nodes-min 1 \
    --nodes-max 5 \
    --asg-access
```

<Info>
  📈 **Why Scale?**
  Scaling ensures your cluster meets changing workloads efficiently.
</Info>

### Deploying Applications

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: sample-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
      - name: sample-app
        image: nginx:latest
        ports:
        - containerPort: 80
```

<Tip>
  💡 **Deploying Applications**
  Use deployments to ensure your applications are scalable and resilient.
</Tip>

### Setting up Load Balancing

```yaml theme={null}
apiVersion: v1
kind: Service
metadata:
  name: sample-app-service
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app: sample-app
```

<Warning>
  ⚠️ **Networking Costs**
  Load balancers incur costs. Use them wisely to optimize expenses.
</Warning>

## Monitoring and Logging

### Installing Metrics Server

```bash theme={null}
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
```

### Setting up CloudWatch Logging

```yaml theme={null}
apiVersion: v1
kind: Namespace
metadata:
  name: amazon-cloudwatch
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: cloudwatch-agent
  namespace: amazon-cloudwatch
spec:
  selector:
    matchLabels:
      name: cloudwatch-agent
  template:
    metadata:
      labels:
        name: cloudwatch-agent
    spec:
      containers:
        - name: cloudwatch-agent
          image: amazon/cloudwatch-agent:latest
```

## Security Best Practices

### Network Policies

```yaml theme={null}
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress
```

<Tip>
  🔒 **Secure Your Cluster**
  Network policies prevent unauthorized communication between pods.
</Tip>

### RBAC Configuration

```yaml theme={null}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: default
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch"]
```

## Cost Optimization

### Resource Quotas

```yaml theme={null}
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-resources
spec:
  hard:
    requests.cpu: "4"
    requests.memory: 8Gi
    limits.cpu: "8"
    limits.memory: 16Gi
```

<Note>
  💡 **Why Resource Quotas?**
  They ensure efficient resource usage and cost control.
</Note>

## Cleanup

### Delete the Cluster

```bash theme={null}
eksctl delete cluster --name my-eks-cluster --region us-west-2
```

<Warning>
  ⚠️ **Data Loss Alert**
  Deleting the cluster will remove all associated resources. Backup data if necessary.
</Warning>

## Troubleshooting

### Common Issues and Solutions

1. **Node Group Issues**

```bash theme={null}
# Check node status
kubectl get nodes
kubectl describe node <node-name>

# Check node group health
eksctl get nodegroup --cluster my-eks-cluster
```

2. **Pod Issues**

```bash theme={null}
# Check pod status
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>
```

3. **Networking Issues**

```bash theme={null}
# Check service status
kubectl get svc
kubectl describe svc <service-name>

# Check DNS resolution
kubectl run test-dns --image=busybox:1.28 -- nslookup kubernetes.default
```

<Info>
  🛠️ **Troubleshooting Tips**
  Most issues can be resolved by checking logs and validating configurations.
</Info>

## Additional Resources

* [Official Amazon EKS Documentation](https://docs.aws.amazon.com/eks/)
* [EKS Workshop](https://www.eksworkshop.com/)
* [Kubernetes Documentation](https://kubernetes.io/docs/)
* [eksctl Documentation](https://eksctl.io/)

<Footer>
  📝 **Note**: This documentation is continuously updated to ensure accuracy. Always refer to official documentation for the latest updates.
</Footer>

## 📧 Contact

For questions or feedback, reach out:

📨 Email: [projects@briankimemia.is-a.dev](mailto:projects@briankimemia.is-a.dev)
🌐 Portfolio: [Brian Kimemia](https://briankimemia.is-a.dev/)
**GitHub:** [BrianKN019](https://github.com/BrianKN019)

***

**Thank you for exploring this project! Let’s innovate and build secure AWS solutions together. 🚀**
