Spin up your first Kubernetes Cluster in under 30 mins.

Akanksha Priyadarshini
May 21 · 5 min read
Image for post
Image for post

Scope of the Article:

Here, we will look at the following things:
1. Package application in a Docker container image.
2. Host the image on Docker Hub.
3. Set up a Kubernetes Cluster locally using minikube.
4. Deploy the image on a locally running Kubernetes cluster.

mkdir hello-world
// package.json
{
"name": "docker_sample_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "akanksha priyadarshini",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.1"
}
}
// server.js'use strict';
const express = require('express');
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello world');
});
app.listen(PORT, HOST);console.log(`App is running on http://${HOST}:${PORT}`);
touch Dockerfile
FROM node:10
WORKDIR /home/node/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
// DockerfileFROM node:10
WORKDIR /home/node/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]
// .dockerignorenode_modules
npm-debug.log
Image for post
Image for post
// sample app directory where Dockerfile is present
cd hello-world
docker build -t <your username>/hello-world .
Image for post
Image for post
docker run -p 8000:8080 -d <your username>/hello-world
Image for post
Image for post
curl -i localhost:8000
Image for post
Image for post
// docker tag <local-image>:<tagname> <new-repo>:<tagname>
docker tag <your-username>/hello-world:latest <your-username>/hello-world:latest
// docker push <new-repo>:<tagname>
docker push <your-username>/hello-world:latest
Image for post
Image for post
minikube start
kubectl create deployment hello-kubernetes --image=<your-username>/hello-world
deployment.apps/hello-kubernetes created
kubectl expose deployment hello-kubernetes --type=NodePort --port=8080
service/hello-kubernetes exposed
kubectl get pods
Image for post
Image for post
minikube service hello-kubernetes --url

The Startup

Medium's largest active publication, followed by +687K people. Follow to join our community.

Sign up for Top Stories

By The Startup

A newsletter that delivers The Startup's most popular stories to your inbox once a month. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Akanksha Priyadarshini

Written by

Engineer @CasaOneUS | Jeffrey Archer Fan | Philonoist | akanksha.io

The Startup

Medium's largest active publication, followed by +687K people. Follow to join our community.

Akanksha Priyadarshini

Written by

Engineer @CasaOneUS | Jeffrey Archer Fan | Philonoist | akanksha.io

The Startup

Medium's largest active publication, followed by +687K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store