While k8s is all good and things works efficiently but sometimes we need to setup and test it in different environments. This guide will help you setup EC2 instance on RedHat9 with minikube and docker (server) and access then minikube dashboard and sample application running on the pod.
Steps
- EC2 Setup
- Make sure to signup for AWS Account and login to the AWS console.
- Look for EC2 under services or search in the search bar. Click and in the EC2 dashboard look for instances(running) and security groups. They can be found on left menu or under resources in the dashboard itself.
- Click Security Groups. You will see a orange button on right corner saying Create Security Group click on it and fill the below details.
- Security group name – minikube-sg
- Description – minikube security group open to all on ipv4
- Inbound rules – Click Add Rule, fill the details below and Click Create Security Group.
- Type – All Traffic
- Source – Anywhere
- By default outbound is open to all. The above will open inbound to all traffic from anywhere. Not suggested for production use.
- Click on instances(running) You will see a orange button on right corner saying Launch Instances click on it and fill the below details.
- Name – minikube
- Instance Image – Select Redhat (Will select RedHat9 by default)
- Instance Type – t3.medium
- Key Pair – Select Existing or Click Create give Key pair name – minukube and leave remaining as default and click create key pair. Make sure to keep the key in a safe location
- Network settings – On do below changes and leave others it is (will launch in public subnet)
- Auto-assign public IP – Enable (If not by default)
- Firewall (security groups) – Select existing security group and in the drop down search for above created security group – minikube-sg and select.
- Configure Storage – Select 30GB and select GP3 – default is 10GB and GP2
- With this we are ready click launch instance. Copy the Public Ip of the instance and Open a terminal in your device. Run the below command to ssh into the instance.

cd Downloads # cd to location where you downloaded the pem file from Key Pair Creation step.
chmod 400 minikube.pem # add permissions to the pem file
ssh -i minikube.pem ec2-user@<public-ip> # minikube is the name of keypair given above if you have given something else use that and provide the public ip of the instance. under Details and Instance Summary you can find Public IPv4 address when you click on the instance.
sudo yum update -y # update the instance using sudo privilege
2. Minikube, Git, kubectl and Docker Installation + Configuration
Docker – https://docs.docker.com/engine/install/ official docker docs
The command below installs latest docker version for RHEL.
# install latest docker
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# check docker version and installation
docker --version
# start docker daemon and check status
sudo systemctl start docker
sudo systemctl status docker
# add ec2-user to docker user group
sudo usermod -aG docker $USER && newgrp docker

Minikube – https://minikube.sigs.k8s.io/docs/start/ official minikube docs
The command below install minikube and configure with configure as driver
# download and install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
sudo rpm -Uvh minikube-latest.x86_64.rpm
# start minikube
minikube start
# check minikube version and installation
minikube --version

Kubectl – https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/ k8s official docs
The command below install kubectl command line tool for interacting with cluster
# download and install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# check version
kubectl version --client

Git – https://git-scm.com/book/en/v2/Getting-Started-Installing-Git git official docs
The command below install Git
# install git and check version
sudo dnf install git-all
git --version

3. Optional – Creating a sample application and pushing to DockerHub
- We are going to take a github sample example project build by someone else as a application and push it to docker hub.
git clone https://github.com/bkanvesh22/node-demo.git # Clone the repo - to make things easy i am using https option
cd node-demo
vi Dockerfile # create dockerfile and paste the code below and save or using
------------------------------------
FROM node:lts-alpine3.18
WORKDIR /app
COPY . .
RUN npm install --production
EXPOSE 8000
CMD ["node", "server.js"]
-------------------------------------
docker build . # build docker image
- Before moving forward we need a dockerhub account. Login or Signup here. https://hub.docker.com/
docker login --username=<docker_hub_username> # login to docker you will be asked for your password
docker images # check for your images
docker tag <image-id> <docker_hub_username>/app:v1.0 <docker_hub_username>/app:v1.0 # push image to dockerhub with name and version where app is name and v1.0 is version don't forget to use the correct dockerhub username.
docker push <docker_hub_username>/app:v1.0 # push the image with the above created tag if no repo exits it will be auto created

4. Creating Resources & Deploying the application in minikube eks
Create a dir called k8s. First We need to setup a mysql database.
- ConfigMap
vi config.yaml # create a config file
------------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: db-config
data:
dbname: "nodeapp"
------------------------
kubectl apply -f config.yaml # create config resources this will create a config called dbname for mysql dbname
- Secrets
vi secrets.yaml # create a config file
--------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: db-config
data:
dbname: "nodeapp"
[ec2-user@ip-172-31-46-142 k8s]$ cat secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
dbpassword: dG9vcg==
--------------------
kubectl apply -f secrets.yaml # create secret resources this will create a secret called dbpassword for mysql dbpassword. the password provided is base64 encoded
echo -n "toor" | base64 # run below command to encode the password
- Persistence Volume
vi pv.yaml # create persistence volume of 10GB for mysql data storage
---------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: db-config
data:
dbname: "nodeapp"
[ec2-user@ip-172-31-46-142 k8s]$ cat secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
dbpassword: dG9vcg==
[ec2-user@ip-172-31-46-142 k8s]$ cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---------------------
kubectl apply -f pv.yaml # create volume resources this will create a persistence volume and setup claim
- MYSQL DB
vi db.yaml # create db config i.e service and deployment
-------------------
apiVersion: v1
kind: Service
metadata:
name: db
spec:
ports:
- port: 3306
selector:
app: db
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: db
spec:
selector:
matchLabels:
app: db
strategy:
type: Recreate
template:
metadata:
labels:
app: db
spec:
containers:
- image: mysql:5.6
name: db
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: dbpassword
- name: MYSQL_DATABASE
valueFrom:
configMapKeyRef:
name: db-config
key: dbname
ports:
- containerPort: 3306
name: db
volumeMounts:
- name: mysql-ps
mountPath: /var/lib/mysql
volumes:
- name: mysql-ps
persistentVolumeClaim:
claimName: mysql-pvc
-------------------
kubectl apply -f db.yaml # create db resources this will create a mysql db service and deployment
- Web App
vi web.yaml # create web resources i.e service and deployment
----------------------
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: NodePort
selector:
app: web
ports:
- protocol: TCP
port: 8000
targetPort: 8000
nodePort: 30200
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: ydvsailendar/app:v1.1
ports:
- containerPort: 8000
----------------------
kubectl apply -f web.yaml # create web resources this will create a web service and deployment
The above all config when applied should show below resources
kubectl get all # get all resources in the default namesapce

5. Accessing application and minikube(k8s) dashboard
- Access Application
minikube service web --url # will give node host and ec2 port

kubectl port-forward --address 0.0.0.0 svc/web 8000:8000 # port forwarding on 8000 as both app runs and we want to access app on port 8000

- Once you see this message go to your browser and hit below url. Should be greeted with below contents.
http://<public-ip>:8000/template.html

- Access Minikube(k8s) Dashboard
- To enable dashboard do which should return as shown in the below image. Keep note of the port from the screenshot
minikube dashboard

- Open you local device terminal and open ssh tunnel using below command
ssh -i <ssh-pem-file-from-ec2-installation> -L <same-port-from-above>:localhost:<port-from-above-image> ec2-user@<public-ip-of-instance> # once this is done copy the above url and paste in the browser and should be able to see something similar to below

Full Code Ref: https://github.com/ydvsailendar/kubernates-oss-observability
Thank you for reading. I will see you in another post.
Cheers and Happy Reading 🙂