Skip to content

Commit

Permalink
Write readme and update config
Browse files Browse the repository at this point in the history
  • Loading branch information
vectornguyen76 committed Nov 26, 2023
1 parent 3dea059 commit 7a33857
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 79 deletions.
270 changes: 196 additions & 74 deletions kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,241 @@
## Deploy a Kubernetes cluster in Local
# Kubernetes Development

1. Start cluster use minikube and docker
## Table of Contents

1. [Architecture](#architecture)
2. [Development Environment Setup](#development-environment-setup)
3. [Production Environment Setup](#production-environment-setup)
4. [Kubernetes Cluster Deployment](#kubernetes-cluster-deployment)
- [Deploy Ingress Nginx](#deploy-ingress-nginx)
- [Installation](#installation)
- [Configuration](#configuration)
- [Verification](#verification)
- [Uninstallation](#uninstallation)
- [Deploy Postgres](#deploy-postgres)
- [Local Installation](#local-installation)
- [EKS Installation](#eks-installation)
- [Local Uninstallation](#local-uninstallation)
- [EKS Uninstallation](#eks-uninstallation)
- [Deploy Backend](#deploy-backend)
- [Deploy Frontend](#deploy-frontend)
- [Deploy Qdrant](#deploy-qdrant)
- [Deploy Image Search](#deploy-image-search)
- [Deploy Text Search](#deploy-text-search)
5. [References](#references)

## Architecture

<p align="center">
<img src="./../assets/kubernetes-architecture.png" alt="Kubernetes Architecture Diagram" />
<br>
<em>Fig: Kubernetes Architecture</em>
</p>

## Development Environment Setup

This section covers the steps to set up a Kubernetes development environment.

### Start Kubernetes with Docker Desktop

Initiate Kubernetes within Docker Desktop for local development.

### Show Node Status

Check the status of Kubernetes nodes.

```
kubectl get nodes
```

### Build and Push Docker Images

Commands to build Docker images and push them to Docker Hub.

```
docker compose build
docker compose push
```

## Production Environment Setup

Guidelines for setting up a Kubernetes environment suitable for production.

### Create and Manage Cluster and NodeGroup

- **Creating a Cluster and Node Group**
```
eksctl create cluster -f cluster-config-eksctl.yaml
```
- **Deleting a Cluster and Node Group**
```
eksctl delete cluster -f cluster-config-eksctl.yaml --disable-nodegroup-eviction
```

### Node Status Verification

Same as in the development environment setup.

### Install aws-ebs-csi-driver

```
kubectl apply -k "github.com/kubernetes-sigs/aws-ebs-csi-driver/deploy/kubernetes/overlays/stable/?ref=release-1.25"
```

Instructions to install the AWS EBS CSI driver in the production environment.

## Kubernetes Cluster Deployment

### Deploy Ingress Nginx

#### Installation

1. **Install Ingress Nginx Controller**
```
helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx
```
minikube start --driver=docker
This command installs the Ingress Nginx controller using Helm.

#### Configuration

1. **Configure Ingress Nginx Service**
```
2. Show node ready
kubectl apply -f ingress-nginx-service.yaml
```
kubectl get nodes
Apply the configuration defined in `ingress-nginx-service.yaml`.

#### Verification

1. **Check Ingress Nginx**
```
3. Build and push image to docker hub
kubectl get ingress
```
docker compose build
docker compose push
Verify the ingress setup by listing all ingress resources.

#### Uninstallation

1. **Remove Ingress Nginx**
```
4. Install Qdrant Helm Chart
helm uninstall ingress-nginx
kubectl delete -f ingress-nginx-service.yaml
```
Uninstall the Ingress Nginx controller and delete its service configuration.

- Add repo
```
helm repo add qdrant https://qdrant.github.io/qdrant-helm
```
- Update repo
```
helm repo update
```
- Install repo
```
helm upgrade -i qdrant-db qdrant/qdrant
```
- Check repo
```
helm list
```
### Deploy Postgres

5. Deploy kubenetes template
#### Local Installation

1. **Apply Postgres Configuration for Local**
```
kubectl apply -f image-search-deployment.yaml,image-search-service.yaml
kubectl apply -f postgres-deployment.yaml,postgres-service.yaml,postgres-pvc.yaml,postgres-pv.yaml
```
Set `storageClassName: standard` in `postgres-pvc.yaml` for local deployment.

#### EKS Installation

1. **Apply Postgres Configuration for EKS**
```
kubectl apply -f postgres-deployment.yaml,postgres-service.yaml,postgres-pvc.yaml
```
Set `storageClassName: gp3` in `postgres-pvc.yaml` for EKS deployment.

#### Local Uninstallation

1. **Remove Postgres in Local**
```
kubectl delete -f postgres-deployment.yaml,postgres-service.yaml,postgres-pvc.yaml,postgres-pv.yaml
```

#### EKS Uninstallation

1. **Remove Postgres in EKS**
```
kubectl delete -f postgres-deployment.yaml,postgres-service.yaml,postgres-pvc.yaml
```

**1. Deploy backend**
### Deploy Backend

1. **Install Backend Service**

```
kubectl apply -f backend-deployment.yaml,backend-service.yaml
```

Deploy the backend service using the specified Kubernetes configurations.

2. **Uninstall Backend Service**
```
kubectl delete -f backend-deployment.yaml,backend-service.yaml
```
Remove the backend service from the cluster.

### Deploy Frontend

1. **Set Up Environment Variables**

- For local deployment: `NEXT_PUBLIC_API_URL=http://localhost/api`
- For production: Retrieve the IP address of the load balancer from `kubectl get ingress` and set `NEXT_PUBLIC_API_URL=http://{ip-address-loadbalancer}/api`.

**2. Deploy Ingress Nginx**
2. **Deploy Frontend Service**

```
helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --create-namespace
kubectl --namespace ingress-nginx get services -o wide -w ingress-nginx-controller
helm uninstall ingress-nginx --namespace ingress-nginx
kubectl apply -f ingress-nginx-service.yaml
kubectl delete -f ingress-nginx-service.yaml
kubectl get ingress
kubectl apply -f frontend-deployment.yaml,frontend-service.yaml
```

**3. Deploy Postgres**
Apply the frontend deployment and service configurations.

3. **Uninstall Frontend Service**
```
kubectl apply -f postgres-deployment.yaml,postgres-service.yaml,postgres-pvc.yaml,postgres-pv.yaml
kubectl delete -f postgres-deployment.yaml,postgres-service.yaml,postgres-pvc.yaml,postgres-pv.yaml
kubectl delete -f frontend-deployment.yaml,frontend-service.yaml
```

**3. Deploy Qdrant**
### Deploy Qdrant

1. **Install Qdrant Database**

```
helm upgrade --install qdrant-db qdrant --repo https://qdrant.github.io/qdrant-helm
```

**4. Deploy Image Search**
Install Qdrant using the Helm chart.

2. **Uninstall Qdrant Database**
```
kubectl apply -f image-search-deployment.yaml,image-search-service.yaml
kubectl delete -f image-search-deployment.yaml,image-search-service.yaml
helm uninstall qdrant-db
kubectl delete pvc -l app.kubernetes.io/instance=qdrant-db
```

6. Show dashboard
### Deploy Image Search

1. **Install Image Search Service**

```
minikube dashboard
kubectl apply -f image-search-deployment.yaml,image-search-service.yaml
```
7. Get service

2. **Uninstall Image Search Service**
```
minikube service image-search-service
kubectl delete -f image-search-deployment.yaml,image-search-service.yaml
```
8. Destroy kubenetes template
- Delete app
```
kubectl delete -f image-search-deployment.yaml,image-search-service.yaml
```
- Uninstall repo
```
helm uninstall qdrant-db
```
- Delete the qdrant volume
```
kubectl delete pvc -l app.kubernetes.io/instance=qdrant-db
```
- Delete cluster
```
minikube delete
```

## Production enviroments
### Deploy Text Search

**1. Create Cluster and NodeGroup**
1. **Install Text Search Service**

```
eksctl create cluster -f cluster-config-eksctl.yaml
eksctl upgrade cluster -f cluster-config-eksctl.yaml
eksctl delete cluster -f cluster-config-eksctl.yaml
```
```
kubectl apply -f text-search-deployment.yaml,text-search-service.yaml
```

2. **Uninstall Text Search Service**
```
kubectl delete -f text-search-deployment.yaml,text-search-service.yaml
```

## References

### Refrence
Useful links for additional information and external resources.

- https://github.com/qdrant/qdrant-helm/tree/main/charts/qdrant
- https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-stack-helm-chart.html
- https://github.com/elastic/cloud-on-k8s/tree/main/deploy/eck-stack
- [EKSCTL Getting Started](https://eksctl.io/getting-started/)
- [AWS EBS CSI Driver Installation Guide](https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/docs/install.md)
- [Qdrant Helm Charts](https://github.com/qdrant/qdrant-helm/tree/main/charts/qdrant)
- [Elastic Cloud on Kubernetes Documentation](https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-stack-helm-chart.html)
- [Elastic Cloud Kubernetes Deployment](https://github.com/elastic/cloud-on-k8s/tree/main/deploy/eck-stack)
24 changes: 23 additions & 1 deletion kubernetes/cluster-config-eksctl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ nodeGroups:
minSize: 1
maxSize: 3
volumeSize: 30
volumeType: gp2
volumeType: gp3
desiredCapacity: 2
iam:
withAddonPolicies:
imageBuilder: true
autoScaler: true
externalDNS: true
certManager: true
appMesh: true
appMeshPreview: true
ebs: true
fsx: true
efs: true
labels:
nodegroup-type: cpu-nodegroup

Expand All @@ -32,6 +43,17 @@ nodeGroups:
# volumeSize: 50
# volumeType: gp3
# desiredCapacity: 1
# iam:
# withAddonPolicies:
# imageBuilder: true
# autoScaler: true
# externalDNS: true
# certManager: true
# appMesh: true
# appMeshPreview: true
# ebs: true
# fsx: true
# efs: true
# labels:
# nodegroup-type: gpu-nodegroup

Expand Down
3 changes: 3 additions & 0 deletions kubernetes/frontend-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ spec:
containers:
- name: frontend-container
image: vectornguyen76/frontend-search-engine:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
6 changes: 3 additions & 3 deletions kubernetes/frontend-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ metadata:
spec:
selector:
app: frontend
type: LoadBalancer
type: NodePort
ports:
- protocol: TCP
port: 5000
targetPort: 5000
port: 3000
targetPort: 3000
7 changes: 7 additions & 0 deletions kubernetes/ingress-nginx-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ spec:
rules:
- http:
paths:
- path: /?(.*)
pathType: ImplementationSpecific
backend:
service:
name: frontend-service
port:
number: 3000
- path: /api/?(.*)
pathType: ImplementationSpecific
backend:
Expand Down
3 changes: 2 additions & 1 deletion kubernetes/postgres-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
# storageClassName: standard
storageClassName: gp3 # Change to an EBS-provisioning StorageClass
resources:
requests:
storage: 1Gi

0 comments on commit 7a33857

Please sign in to comment.