From ceb4cf5a9cb9fd5053949b2309e3b05e1c6e0559 Mon Sep 17 00:00:00 2001 From: Conor Heffron Date: Fri, 29 Nov 2024 17:29:49 +0000 Subject: [PATCH] #158 Add documentation on k8s local cluster deployment & run (#164) * #158 Add documentation on k8s local cluster deployment & run * Update pom.xml --- README.md | 85 +++++++++++++++++++- k8s/ironoc.yaml | 207 ++++++++++++++++++++++++++++++++++++++++++++++++ pom.xml | 2 +- 3 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 k8s/ironoc.yaml diff --git a/README.md b/README.md index c474ee3c..44e51019 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ Personal website / portfolio [https://www.ironoc.net/](https://www.ironoc.net/) ## Tech Stack -Java 21 (LTS), Spring Boot 3.3, ReactJs 18, Maven 3.8, HTML5+CSS, Docker / Bash, AWS +Java 21 (LTS), Spring Boot 3.3, ReactJs 18, Maven 3.8, HTML5+CSS, + Docker / Bash, AWS, minikube, & kubectl. ## Run without cloning project: ``` @@ -27,7 +28,13 @@ docker run -d --restart=always -p 8080:8080 conorheffron/ironoc ## Run after project checkout (JDK 21 & Maven 3.8.3 required) Build / Run App: ``` -mvn clean package spring-boot:run +mvn clean package + +mvn -DAWS_ACCESS_KEY_ID= \ + -DAWS_REGION= \ + -DAWS_SECRET_ACCESS_KEY= \ + -DAWS_SESSION_TOKEN= \ + spring-boot:run ``` ![image](screen-grabs/IDEA-Intellj-run.png) @@ -51,4 +58,78 @@ docker-compose down # Screenshot ![Home](screen-grabs/home-page.png) +# Local k8s cluster with Minikube: + +MiniKube Install Notes for mac users +``` +brew install kubectl +brew install virtualbox +brew install minikube +``` + +``` +Oracle VirtualBox Manager v7.1.4 + +% kubectl version +Client Version: v1.30.2 +Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 +Server Version: v1.31.0 + +% minikube version +minikube version: v1.34.0 +commit: 210b148df93a80eb872ecbeb7e35281b3c582c61 + +% docker version +Client: +Version: 27.3.1 +API version: 1.47 +Go version: go1.22.7 +Git commit: ce12230 +Built: Fri Sep 20 11:38:18 2024 +OS/Arch: darwin/amd64 +Context: desktop-linux +``` + +- Open terminal +``` +cd k8s/ + +# (clean-up & again after local testing complete) +minikube delete + +minikube start --driver=docker +kubectl cluster-info + +minikube dashboard +``` + +### Then change namespace in browser from default to ironoc-ns +- i.e. http://127.0.0.1:56414/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/pod?namespace=ironoc-ns +### Open New tab in terminal & create deployment +``` +docker image build -t ironoc . +minikube image load ironoc:latest + +kubectl create ns ironoc-ns + +kubectl apply -f k8s/ironoc.yaml --namespace=ironoc-ns + +kubectl get pods --namespace=ironoc-ns +kubectl get deployment --namespace=ironoc-ns + +kubectl expose deployment ironoc-app-deployment --type=NodePort --namespace=ironoc-ns + +kubectl get svc --namespace=ironoc-ns + +minikube service ironoc-app-deployment --url --namespace=ironoc-ns +``` + +### Open New tab in terminal & tail logs +``` +% kubectl get pods --namespace=ironoc-ns +NAME READY STATUS RESTARTS AGE +ironoc-app-deployment-6d84f75b44-kpqpj 1/1 Running 0 3m37s + +kubectl logs ironoc-app-deployment-6d84f75b44-kpqpj -f --namespace=ironoc-ns +``` diff --git a/k8s/ironoc.yaml b/k8s/ironoc.yaml new file mode 100644 index 00000000..4b008754 --- /dev/null +++ b/k8s/ironoc.yaml @@ -0,0 +1,207 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: ironoc-app-deployment + managedFields: + - apiVersion: apps/v1 + fieldsType: FieldsV1 + fieldsV1: + 'f:spec': + 'f:replicas': {} + manager: vpa-recommender + operation: Update + subresource: scale + - apiVersion: apps/v1 + fieldsType: FieldsV1 + fieldsV1: + 'f:metadata': + 'f:labels': + .: {} + 'f:app': {} + 'f:spec': + 'f:progressDeadlineSeconds': {} + 'f:revisionHistoryLimit': {} + 'f:selector': {} + 'f:strategy': + 'f:rollingUpdate': + .: {} + 'f:maxSurge': {} + 'f:maxUnavailable': {} + 'f:type': {} + 'f:template': + 'f:metadata': + 'f:labels': + .: {} + 'f:app': {} + 'f:spec': + 'f:containers': + 'k:{"name":"ironoc-app-sha256-1"}': + .: {} + 'f:image': {} + 'f:imagePullPolicy': {} + 'f:name': {} + 'f:resources': {} + 'f:terminationMessagePath': {} + 'f:terminationMessagePolicy': {} + 'f:dnsPolicy': {} + 'f:restartPolicy': {} + 'f:schedulerName': {} + 'f:securityContext': {} + 'f:terminationGracePeriodSeconds': {} + manager: unknown + operation: Update + time: '2024-10-15T11:53:53Z' + - apiVersion: apps/v1 + fieldsType: FieldsV1 + fieldsV1: + 'f:metadata': + 'f:annotations': + 'f:deployment.kubernetes.io/revision': {} + 'f:status': + 'f:availableReplicas': {} + 'f:conditions': + .: {} + 'k:{"type":"Available"}': + .: {} + 'f:lastTransitionTime': {} + 'f:lastUpdateTime': {} + 'f:message': {} + 'f:reason': {} + 'f:status': {} + 'f:type': {} + 'k:{"type":"Progressing"}': + .: {} + 'f:lastTransitionTime': {} + 'f:lastUpdateTime': {} + 'f:message': {} + 'f:reason': {} + 'f:status': {} + 'f:type': {} + 'f:observedGeneration': {} + 'f:readyReplicas': {} + 'f:replicas': {} + 'f:unavailableReplicas': {} + 'f:updatedReplicas': {} + manager: kube-controller-manager + operation: Update + subresource: status + time: '2024-10-15T12:04:58Z' + name: ironoc-app-deployment + namespace: ironoc-ns +spec: + replicas: 1 + selector: + matchLabels: + app: ironoc-app-deployment + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + labels: + app: ironoc-app-deployment + spec: + containers: + - image: ironoc:latest + imagePullPolicy: Never + ports: + - containerPort: 8080 + name: ironoc-app-sha256-1 + resources: + limits: + ephemeral-storage: 1Gi + requests: + cpu: 500m + ephemeral-storage: 1Gi + memory: 2Gi + securityContext: + capabilities: + drop: + - NET_RAW + securityContext: + seccompProfile: + type: RuntimeDefault + tolerations: + - effect: NoSchedule + key: kubernetes.io/arch + operator: Equal + value: amd64 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + labels: + app: ironoc-app-deployment + managedFields: + - apiVersion: autoscaling/v2 + fieldsType: FieldsV1 + fieldsV1: + 'f:metadata': + 'f:labels': + .: {} + 'f:app': {} + 'f:spec': + 'f:maxReplicas': {} + 'f:metrics': {} + 'f:minReplicas': {} + 'f:scaleTargetRef': + 'f:apiVersion': {} + 'f:kind': {} + 'f:name': {} + manager: unknown + operation: Update + time: '2024-10-15T11:53:54Z' + - apiVersion: autoscaling/v2 + fieldsType: FieldsV1 + fieldsV1: + 'f:status': + 'f:conditions': + .: {} + 'k:{"type":"AbleToScale"}': + .: {} + 'f:lastTransitionTime': {} + 'f:message': {} + 'f:reason': {} + 'f:status': {} + 'f:type': {} + 'k:{"type":"ScalingActive"}': + .: {} + 'f:lastTransitionTime': {} + 'f:message': {} + 'f:reason': {} + 'f:status': {} + 'f:type': {} + 'k:{"type":"ScalingLimited"}': + .: {} + 'f:lastTransitionTime': {} + 'f:message': {} + 'f:reason': {} + 'f:status': {} + 'f:type': {} + 'f:currentMetrics': {} + 'f:currentReplicas': {} + 'f:desiredReplicas': {} + 'f:lastScaleTime': {} + manager: vpa-recommender + operation: Update + subresource: status + time: '2024-10-15T12:03:57Z' + name: ironoc-app-deployment-hpa-kbij + namespace: ironoc-ns +spec: + maxReplicas: 1 + metrics: + - resource: + name: cpu + target: + averageUtilization: 80 + type: Utilization + type: Resource + minReplicas: 1 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: ironoc-app-deployment diff --git a/pom.xml b/pom.xml index 87f0a19f..2f4765d5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ conorheffron ironoc - 5.2.12 + 5.3.1 war