In this blog, we will walk through the deployment of a sample racing game on an EKS cluster,
utilizing key Kubernetes components like Pods, Services, Persistent Volumes (PV), Persistent
Volume Claims (PVC), and also demonstrate how to monitor and manage the deployed resources
using the Kubernetes Dashboard.
Prerequisites:
- AWS account with IAM roles configured for EKS.
- AWS CLI, kubectl, and eksctl installed on your local machine.
- A basic understanding of Kubernetes concepts like Pods, Services, PV, PVC, and Deployments.
Step 1: Set Up Your EKS Cluster
Before we deploy the game, let's set up an EKS cluster using eksctl, which simplifies the process
of creating and managing EKS clusters.
eksctl create cluster --name eks-workshop --region eu-west-1 --nodegroup-name
eks-workshop-default-node --node-type m5.large --nodes 3 --nodes-min 1 --nodes-
max 4 --managed
This command creates an EKS cluster named eks-workshop in the us-east-1 region with 3 worker nodes of type m5.large
Step 2: Configure kubectl to Use Your EKS Cluster
Once your EKS cluster is up and running, configure your kubectl to interact with the new cluster.
aws eks --region eu-west-1 update-kubeconfig --name racing eks-workshop
Step 3: Create the Kubernetes Deployment for the Racing
Game
We'll now deploy the sample racing game by creating a Deployment. This defines the desired
state of your application, including the number of replicas and container image to use.
Create a racing-game-deployment.yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: racing-game-deployment
spec:
replicas: 3
selector:
matchLabels:
app: racing-game
template:
metadata:
labels:
app: racing-game
spec:
containers:
- name: racing-game
image: misterbisson/sample-racing-game:latest
ports:
- containerPort: 8080
This YAML file creates a Deployment with 3 replicas of the racing-game container, pulling the
misterbisson/sample-racing-game:latest image.
Apply the deployment to the cluster:
kubectl apply -f racing-game-deployment.yaml
Step 4: Expose the Racing Game as a Service
Now, expose the racing game via a Kubernetes Service so that it can be accessed externally.
Create a racing-game-service.yaml file:
apiVersion: v1
kind: Service
metadata:
name: racing-game-service
spec:
selector:
app: racing-game
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: NodePort
This YAML file creates a NodePort service that exposes the racing game on port 80 .
Apply the service configuration:
kubectl apply -f racing-game-service.yaml
kubectl get svc racing-game-service
Step 5: Adding Persistent Volumes (PV) and Persistent
Volume Claims (PVC)
To retain data even when the pods are rescheduled or restarted, we’ll use Persistent Volumes
(PV) and Persistent Volume Claims (PVC).
First, create a Persistent Volume definition in racing-game-pv.yaml :
apiVersion: v1
kind: PersistentVolume
metadata:
name: racing-game-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data/racing-game"
persistentVolumeReclaimPolicy: Retain
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: racing-game-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Apply the PV and PVC to the cluster:
kubectl apply -f racing-game-pv.yaml
kubectl apply -f racing-game-pvc.yaml
Afterward, you can check the status of your PVC by running:
kubectl get pvc racing-game-pvc
If everything is set up correctly, Kubernetes will bind the PVC to the PV, ensuring data persistence.
Step 6: Verify Components in Kubernetes Dashboard
The Kubernetes Dashboard is a great way to monitor your Kubernetes resources visually. To
deploy and access the Kubernetes Dashboard, follow these steps:
- Install the Kubernetes Dashboard:
kubectl apply -f
https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
- Create an admin user for accessing the Dashboard with appropriate permissions. Create a file named admin-user.yaml :
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
Apply this configuration:kubectl apply -f admin-user.yaml
3. Get the token to log into the Dashboard:
kubectl -n kubernetes-dashboard create token admin-user
4. Access the Dashboard:
To open the Dashboard, use kubectl proxy :
kubectl proxy
Now, navigate to http://localhost:8001/ui in your web browser and log in using the token you
retrieved earlier.
From the Dashboard, you can view your deployed Pods, Services, PVCs, and more, helping you monitor and manage the game deployment efficiently.
Conclusion
By following these steps, we’ve successfully deployed a sample racing game on an EKS cluster,using Kubernetes components like Pods, Services, PV, and PVC to manage persistent storage.
Additionally, we’ve demonstrated how to monitor and manage these resources via the Kubernetes Dashboard.
This setup provides a scalable and easy-to-manage deployment for applications running on AWS EKS, ensuring data persistence and offering a visual interface to monitor the entire application lifecycle.
**Happy Learning
Prithiviraj Rengarajan
DevOps Engineer**
Top comments (0)