This project creates a container that displays a basic web page with the name and IP address of the Pod. It is built using Next.js and delivered by Nginx for deployment into Kubernetes, and intended to be used as part of a lab exercise or an intructor-led walkthrough.
When running it presents a basic web page displaying Pod information:
If Node.js is installed locally, you can run the following commands from within the cloned directory to verify that the application works:
npm install
npm run dev
This will start a local web server running on port 3000
. The application can then be verified by visiting http://localhost:3000 in a web browser.
To build the container image you will need to have Docker installed. To build the image locally, run the following shell script inside the k8s-frontend-podinfo
directory:
./docker-build.sh
If the build completes successfully, you will then be asked if you want to push the image. For this to succeed you will need to be authenticated to the specified registry with the appropriate account.
If you want to change the fully-qualified image name (including the image registry) edit the container.json
file within the public/data
directory.
docker-build.sh
file directly.
This is because the container.json
file is used by both the Docker build script and the Next.js application at run time.
registry
andnamespace
are optional- Note that the values should not end with a trailing slash
repository
andtags
are mandatorytags
is an array that should contain at least one value
{
"image": {
"registry": "docker.io",
"namespace": "trainingdemos",
"repository": "k8s-frontend-podinfo",
"tags": [
"latest", "1.0", "1.0.1"
]
}
}
A container image for this project has been made available on the Docker Hub for public use. To run the image using Docker you can use the following command:
docker run --rm -p 80:80 trainingdemos/k8s-frontend-podinfo
This will start an Nginx web server running on port 80
to serve the application. You can verify that the website is working by visiting http://localhost in a web browser.
The containerPort
in the Pod spec should be set to port 80
and then access to the Pod should be opened up using a Service object along with a NodePort or Ingress.
Here is an example Pod object configuration:
apiVersion: v1
kind: Pod
metadata:
name: k8s-frontend-podinfo
labels:
frontend: basic
spec:
containers:
- name: k8s-basic-frontend
image: trainingdemos/k8s-frontend-podinfo:latest
ports:
- containerPort: 80
MIT (See LICENSE file)