This project demonstrates the basic workings of Docker and Kubernetes, focusing on:
- A simple Hello-world Docker container.
- A Python Flask ping-pong service that responds to "ping".
- A Go program for pattern detection in string.
Docker was pre-installed on my machine. I enabled Kubernetes in Docker to deploy and manage containerized applications.
I pulled the hello-world Docker image from Docker Hub and ran it in a Docker container on my local machine. This service prints "Hello, Docker!" to the Terminal.
I deployed the hello-world Docker container using Kubernetes. The hello-world-docker folder contains a hello-world.yaml file, which defines the application and its deployment to a Kubernetes cluster.
-
API Version:
TheapiVersionisv1, which indicates the use of a stable Kubernetes API. -
Kind:
ThekindisPod, which specifies that the deployment will run thehello-worldcontainer inside a Kubernetes Pod. -
Metadata:
name: The name of the Pod, which is set tohello-world.
-
Spec:
containers: Contains the configuration for the container:name: The name of the container, which ishello-world.image: Specifies the Docker image to use, which ishello-world.
- Pull the Docker Image:
Downloaded thehello-worldimage from Docker Hub using the following command:docker pull hello-world
- Run the Docker Container:
Started the container locally to see the
"Hello from Docker!"message:
docker run hello-world- Apply the Kubernetes Configuration: The hello-world.yaml file contains deployment specifications. Used it to deploy the application to a Kubernetes cluster:
kubectl apply -f hello-world-docker/hello-world.yamlThis service implements a simple Python script that responds to the /ping endpoint with the message "pong". The service listens on port 5000.
The code for this service is located in the ping-pong-python folder. It contains the following files:
This file contains the Python code to:
- Listen on port
5000. - Respond to the
/pingendpoint with the message"pong".
This file contains the configuration to create a Docker image for the ping-pong-python.py script.
This file contains the Kubernetes deployment configuration for the Ping Pong service.
- apiVersion:
apps/v1(a stable API version for Kubernetes). - kind:
Deployment(to manage multiple replicas of pods running the Ping Pong service). - metadata:
name: Name of the Deployment (ping-pong-deployment).
- spec:
- selector:
matchLabels: Identifies the pod with the labelname: ping-pong-app.
- template:
- metadata:
labels: Sets the pod label toname: ping-pong-app.
- spec:
- containers:
image: The container image (ashwin0711/ping-pong-app).name: The container name (ping-pong-app-container).ports:containerPort: Exposes port5000from the container.
- containers:
- metadata:
- selector:
This file automates the following tasks:
- Building the Docker image for the Ping Pong service.
- Deploying the containerized application to Kubernetes.
This program checks if a string follows a specific pattern:
- Starts with
"i"or"I". - Contains
"a"or"A"anywhere in the middle. - Ends with
"n"or"N".
The code for this program is located in the main.go file.
- Reads an input string.
- Evaluates the string against the defined pattern.
- Returns whether the string matches the pattern.