diff --git a/README.md b/README.md index 100443d..2a8ee89 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,13 @@ containerization, CI/CD, Kubernetes deployment, and Terraform infrastructure. ```text http-server-devops/ -├── .github/ +├── .github/ # GitHub Actions workflows │ └── workflows/ │ └── docker-publish.yml -├── k8s/ # Kubernetes manifests +├── k8s/ # Kubernetes manifests +│ └── namespace.yaml +│ └── deployment.yaml +│ └── service.yaml ├── terraform/ # Terraform configuration ├── Dockerfile ├── go.mod @@ -33,7 +36,7 @@ http-server-devops/ - [x] Task 1: HTTP Server - [x] Task 2: Dockerize - [x] Task 3: CI/CD Pipeline -- [ ] Task 4: Kubernetes Deployment +- [x] Task 4: Kubernetes Deployment - [ ] Task 5: Terraform Configuration ## Installation & Usage @@ -137,3 +140,83 @@ permissions: ``` No external Docker registry credentials are required. + +## Kubernetes Deployment + +The application can be deployed to a local Kubernetes cluster using minikube. + +### Start minikube + +```bash +minikube start -p http-server-devops +``` + +### Check cluster status + +```bash +minikube status -p http-server-devops +kubectl config current-context +kubectl get nodes +``` + +### Deploy application + +```bash +kubectl apply -f k8s/namespace.yaml +kubectl apply -f k8s/deployment.yaml +kubectl apply -f k8s/service.yaml +``` + +### Check resources + +```bash +kubectl get all -n http-server-devops +``` + +### Access application + +```bash +minikube service http-server -n http-server-devops --url -p http-server-devops +``` + +Use the returned URL: + +```bash +curl +``` + +Expected response: + +```text +Hello, World! +``` + +Health check + +```bash +curl /health +``` + +Expected response: + +```text +ok +``` + +### Remove deployment + +```bash +kubectl delete namespace http-server-devops +``` + +### Delete local cluster + +```bash +minikube delete -p http-server-devops +``` + +The deployment uses the released image: + +```text +ghcr.io/aldriondev/http-server-devops:latest +``` diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..c51cc1b --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: http-server + namespace: http-server-devops + labels: + app: http-server +spec: + replicas: 2 + selector: + matchLabels: + app: http-server + template: + metadata: + labels: + app: http-server + spec: + containers: + - name: http-server + image: ghcr.io/aldriondev/http-server-devops:latest + imagePullPolicy: Always + ports: + - containerPort: 8080 + env: + - name: PORT + value: "8080" + resources: + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "128Mi" + cpu: "250m" + readinessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 3 + periodSeconds: 10 + livenessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 20 diff --git a/k8s/namespace.yaml b/k8s/namespace.yaml new file mode 100644 index 0000000..49036b6 --- /dev/null +++ b/k8s/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: http-server-devops diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..06ac193 --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: http-server + namespace: http-server-devops + labels: + app: http-server +spec: + type: NodePort + selector: + app: http-server + ports: + - protocol: TCP + port: 80 + targetPort: 8080