This guide is tailored for running the project on Windows 11 using Docker Desktop (which includes built-in Kubernetes support). It assumes basic knowledge of Java, Maven, Docker, and Kubernetes for learning purposes. The project deploys three microservices: shopfront (Spring Boot), productcatalogue (Dropwizard), and stockmanager (Spring Boot).
- Java 8: Download from Oracle or use OpenJDK. Set JAVA_HOME and add to PATH.
- Maven: Download from Apache Maven. Set MAVEN_HOME and add %MAVEN_HOME%\bin to PATH. Verify with mvn -version.
- Docker Desktop: Download and install. Enable Kubernetes in Settings > Kubernetes. Verify with kubectl version.
- Git: Install if needed. Ensure project is in d:/Projects/Kubernetes_java_Deployment.
- Docker Hub Account: Create account. Replace 'praveensingam1994' with your username in commands.
Use Command Prompt as Administrator.
- cd d:\Projects\Kubernetes_java_Deployment
- Ensure all files are present.
- cd shopfront && mvn clean install -DskipTests
- cd ..\productcatalogue && mvn clean install -DskipTests
- cd ..\stockmanager && mvn clean install -DskipTests
- Check target/*.jar files created.
- cd shopfront && docker build -t yourusername/shopfront:latest .
- cd ..\productcatalogue && docker build -t yourusername/productcatalogue:latest .
- cd ..\stockmanager && docker build -t yourusername/stockmanager:latest .
- docker images to verify.
- docker login
- docker push yourusername/shopfront:latest
- docker push yourusername/productcatalogue:latest
- docker push yourusername/stockmanager:latest
- cd ..\kubernetes
- kubectl apply -f shopfront-service.yaml
- kubectl apply -f productcatalogue-service.yaml
- kubectl apply -f stockmanager-service.yaml
- kubectl get pods and kubectl get services to verify.
- kubectl get services for ports.
- Browser: http://localhost:8010 (shopfront), http://localhost:8020/products (productcatalogue), http://localhost:8030/stocks (stockmanager).
kubectl port-forward deployment/shopfront 8010:8010
kubectl port-forward deployment/productcatalogue 8020:8020
kubectl port-forward deployment/stockmanager 8030:803
- Shopfront: http://localhost:8010
- Product Catalogue: http://localhost:8020/products
- Stock Manager: http://localhost:8030/stock
- kubectl logs
- kubectl describe pod/service
- Clean up: kubectl delete -f .yaml
- kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
- kubectl create serviceaccount admin-user -n kubernetes-dashboard
- kubectl create clusterrolebinding admin-user --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:admin-user
- kubectl -n kubernetes-dashboard create token admin-user
- kubectl proxy
- Open your browser and navigate to:http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
Select "Token" authentication method Paste the token from Step 4 Click "Sign in"
kubectl get pods -n kubernetes-dashboard
kubectl get serviceaccount -n kubernetes-dashboard
kubectl get clusterrolebinding admin-user
Token not working: Generate a new token with kubectl -n kubernetes-dashboard create token admin-user Proxy connection issues: Ensure kubectl proxy is running in a separate termina Dashboard not accessible: Verify pods are running with kubectl get pods -n kubernetes-dashboard
Press Ctrl + C in the terminal where kubectl proxy is running.
- Download kubectl binary
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.20.4/2021-04-12/bin/linux/amd64/kubectl
- curl -o kubectl: Downloads a file and saves it as "kubectl"
- Downloads from Amazon EKS S3 bucket
- Specific version: Kubernetes 1.20.4 for Linux AMD64 architecture
- Make kubectl executable
chmod +x ./kubectl
- chmod +x: Adds execute permission to the file
- Makes the kubectl binary executable
- Create bin directory
mkdir -p $HOME/bin
- mkdir -p: Creates directory (with parents if needed)
- $HOME/bin: Creates a bin folder in user's home directory
- Copy kubectl to bin directory
cp ./kubectl $HOME/bin/kubectl
- Copies the kubectl binary to the newly created bin directory
- Add to PATH temporarily
export PATH=$HOME/bin:$PATH
- Adds $HOME/bin to the beginning of PATH environment variable
- Temporary: Only lasts for current terminal session
- Make PATH change permanent
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
- echo: Outputs the text
-
~/.bashrc: Appends the line to .bashrc file
- .bashrc runs every time you open a new terminal
- Permanent: Makes the PATH change persistent
- Reload bash configuration
source $HOME/.bashrc
- source: Executes the file in current shell
- Reloads .bashrc to apply the PATH changes immediately
- Verify installation
kubectl version --short --client
- Tests if kubectl is working
- --short: Shows abbreviated version info
- --client: Only shows client version (no cluster connection needed)
yum install docker -y systemctl start docker systemctl enable docker
https://minikube.sigs.k8s.io/docs/start/
Step1: Take EC2 Instance with t2.MEDIUM instance type.
Step2: Create IAM Role with Admin policy for eks-cluster and attach to ec2-instance.
Step3: Install kubectl
- curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mkdir -p $HOME/bin
- cp ./kubectl $HOME/bin/kubectl
- export PATH=$HOME/bin:$PATH
- echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
- source $HOME/.bashrc
- kubectl version --short --client
Step4: 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/bin
- eksctl version
Step5: MASTER Cluster creation:
- eksctl create cluster --name=eksdemo
--region=us-west-1
--zones=us-west-1b,us-west-1c
--without-nodegroup
Step6: Add Iam-Oidc-Providers:
- eksctl utils associate-iam-oidc-provider
--region us-west-1
--cluster eksdemo
--approve
Step7: WORKER NODE Create node-group:
- eksctl create nodegroup --cluster=eksdemo
--region=us-west-1
--name=eksdemo-ng-public
--node-type=t2.medium
--nodes=2
--nodes-min=2
--nodes-max=4
--node-volume-size=10
--ssh-access
--ssh-public-key=gurus-test
--managed
--asg-access
--external-dns-access
--full-ecr-access
--appmesh-access
--alb-ingress-access
-
Cluster: eksdemo
-
Region: us-west-1
-
Node Group Name: eksdemo-ng-public
-
Instance Type: t2.medium
-
Scaling: 2-4 nodes (min 2, max 4)
-
Storage: 10GB per node
-
SSH Access: Enabled with key Praveen-test
-
Managed: AWS manages the nodes
-
Additional Access: ECR, AppMesh, ALB Ingress, External DNS, ASG
//eksctl delete nodegroup --cluster=eksdemo --region=us-east-1 --name=eksdemo-ng-public
- Note: This is commented with // and has a region mismatch (us-east-1 vs us-west-1)
//eksctl delete cluster --name=eksdemo --region=us-west-1
Deploying Java Applications with Docker and Kubernetes
-
Build each project ->> mvn clean install -DskipTests
-
Create docker hub account
-
Build the image in local -> docker build -t praveensingam1994/shopfront:latest .
-
docker build -t gurus41/productcatalogue:latest .
-
docker build -t gurus41/stockmanager:latest .
- Push the image to your docker hub -> docker push praveensingam1994/shopfront:latest
- docker push gurus41/productcatalogue:latest
- docker push gurus41/stockmanager:latest
- Go to kubernetes folder and create the pods ->
- kubectl apply -f shopfront-service.yaml
- kubectl apply -f productcatalogue-service.yaml
- kubectl apply -f stockmanager-service.yaml
- minikube service servicename ->
- minikube service shopfront
- minikube service productcatalogue
- minikube service stockmanager
- Hit the url in browser ->
- ORDER TO BUILD AND DEPLOY shopfront -> productcatalogue -> stockmanager Endpoint for product --> /products Endpoint for stock --> /stocks
- Check Pod Status: kubectl get pods - Ensure all pods are Running (not Pending/CrashLoopBackOff).
- Check Service Exposure: kubectl get services - Verify NodePort services are created with external IPs.
- Check Logs: kubectl logs - Look for startup errors or health check failures.
- Port Conflicts: Ensure ports 8010, 8020, 8030 are free. Use netstat -ano | findstr :8010 to check.
- Kubernetes Context: kubectl config current-context - Should be 'docker-desktop'.
- Docker Desktop: Ensure Kubernetes is enabled and running in Docker Desktop dashboard.
- Firewall: Temporarily disable Windows Firewall or allow ports in Advanced Settings.
- Restart: Restart Docker Desktop and redeploy if issues persist.
- Health Checks: Pods may fail liveness probes; check YAML paths (e.g., /health for shopfront/stockmanager, /healthcheck for productcatalogue).
- Image Pull: If pods stuck in ImagePullBackOff, ensure images are pushed and accessible.
- Concepts: Pods, Deployments, Services (NodePort), Liveness Probes.
- Experiment: Change replicas in YAML and reapply.
- Resources: Kubernetes Docs, Docker Desktop Kubernetes.
- Issues: Ensure Docker Desktop/Kubernetes enabled.