Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Docker and Kubernetes Demo Project

Here’s a step-by-step guide to creating a simple project with a web server and app server using Docker and Kubernetes on Ubuntu, ensuring that the Docker image is accessible from Kubernetes without any errors:

Step 1

1. Create a new directory for your project:

mkdir web-app-project
cd web-app-project



2. Create a file named Dockerfile and open it in a text editor:

Vi Dockerfile
FROM nginx:latest

COPY index.html /usr/share/nginx/html/index.html

3. Create an index.html file in the same directory and add your desired HTML content.

<!DOCTYPE html>
<html>
<head>
    <title>Web Server</title>
</head>
<body>
    <h1>Welcome to the Web Server!</h1>
</body>
</html>
Code language: HTML, XML (xml)

4. Build the Docker image:

docker build -t web-server-image .



Step 2:

Test the Docker Image

1. Run a Docker container using the newly created image:

docker run -d -p 8080:80 web-server-imageCode language: CSS (css)

2. Access the web server by opening your web browser and visiting http://localhost:8080. You should see the web server content you defined in the index.html file.

3. Stop the Docker container:

docker stop <container-id>Code language: HTML, XML (xml)

To push an image to Docker Hub registry, you can follow these steps:

  • Tag the image with the Docker Hub repository name: Before pushing the image, you need to tag it with the Docker Hub repository name. The repository name should follow the format: <username>/<repository-name>
docker tag <image-name> <username>/<repository-name>:<tag>Code language: HTML, XML (xml)
  • Replace <image-name> with the name of the image you built, <username> with your Docker Hub username, <repository-name> with the desired name for your repository, and <tag> with the version or tag you want to assign to the image.
  • Log in to Docker Hub: Authenticate yourself with your Docker Hub account to gain access to your repositories.
docker login
  • Push the image to Docker Hub: Once you’re logged in, you can push the tagged image to Docker Hub.
docker push <username>/<repository-name>:<tag>Code language: HTML, XML (xml)
  • Replace <username>/<repository-name>:<tag> with the same repository name and tag you used in the previous step.
  • The Docker image will be pushed to Docker Hub, and you’ll see progress information during the push process.
  • Verify the pushed image: Go to the Docker Hub website (https://hub.docker.com/) and log in with your Docker Hub account. Navigate to your repository, and you should see the pushed image listed with the specified tag.

Examples

docker tag app-server jami12345/project_1:app-server
docker push jami12345/project_1:app-server

or

During Build Use below steps:

docker build -t jami12345/guestbook-app:latest .
docker push jami12345/guestbook-app:latest

Step 3:

Set Up Kubernetes Cluster

Install and set up a Kubernetes cluster on your Ubuntu machine. You can use Minikube for a local cluster setup or set up a cluster on a cloud provider like AWS, Azure, or GCP. Follow the respective documentation for your chosen method.

Step 4:

Deploy the Web Server and App Server

1. Create a file named web-server-deployment.yaml and define the Kubernetes Deployment for the web server:

apiVersion: apps/v1
kind: Deployment
metadata:
name: web-server-deployment
spec:
replicas: 1
selector:
matchLabels:
app: web-server
template:
metadata:
labels:
app: web-server
spec:
containers:
- name: web-server
image: jami12345/project_1:web-server 
ports:
- containerPort: 80



2. Apply the Kubernetes deployment configuration to deploy the web server:

kubectl apply -f web-server-deployment.yamlCode language: CSS (css)

3. Verify that the deployment is created:

kubectl get deploymentsCode language: JavaScript (javascript)

4. Create a file named web-server-service.yaml and define the Kubernetes Service for the web server:

apiVersion: v1
kind: Service
metadata:
name: web-server-service
spec:
selector:
app: web-server
ports:
- protocol: TCP
port: 80
targetPort: 80
type: Nodeport

5. Apply the Kubernetes service configuration to expose the web server:

kubectl apply -f web-server-service.yamlCode language: CSS (css)

6. Verify that the service is created:

kubectl get servicesCode language: JavaScript (javascript)

7. Access the web server:

Look for the service entry and note the assigned PORT number. You can access the Guestbook application by visiting http://<NodeIP>:<PORT> in your web browser.

Note: – To change service type to Node port

kubectl patch service app-server-service -p '{"spec": {"type": "NodePort"}}'Code language: JavaScript (javascript)

or

Step 8:

Access the application

To access the application, you can use port forwarding. Run the following command:

kubectl port-forward service/web-app-service 8080:80

To access the application, you can use port forwarding. Run the following command:

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
MotoShare.in is your go-to platform for adventure and exploration. Rent premium bikes for epic journeys or simple scooters for your daily errands—all with the MotoShare.in advantage of affordability and ease.

Related Posts

List of containerized storage orchestration in Kubernetes

List of Containerized Storage Orchestration Solutions in Kubernetes (2026 Edition) Kubernetes has become excellent at orchestrating stateless applications, but stateful workloads still need a proper storage layer….

Read More

Understanding Authentication & Authorization in kubernetes

Authentication – How User’s access should be allowed? The process or action of verifying the identity of a user or process.Authorization – What Access and till what…

Read More

Kubernetes 1.23.6 Cluster Setup Master and Worker in Ubuntu 20.04

Latest doc – https://github.com/certifications-tutorials/kubernetes-cluster-setup Following commands would help you to create 1 Master and 1 Node in same VM. Run Following commands in Master Node Run following…

Read More

Kubernetes PersistentVolume, PersistentVolumeClaim, volume using hostPath

pv.yaml $ kubectl create -f pv.yaml $ kubectl get pv pvc.yaml $ kubectl create -f pvc.yaml $ kubectl get pvc pod.yaml Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert…

Read More

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Here’s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x