Notes and resources for GHW December stream on Deploying your first Kubernetes Cluster
Watch the recording of all three parts here:
- Install Git
- Install Node
- Install Docker Desktop
- Create an account on Docker Hub
- Login to Docker Desktop with your docker account
- Login to Docker CLI
docker login
(more info)
- Clone this repo
- https:
https://github.com/ashwinexe/GHW-December.git
- ssh:
git@github.com:ashwinexe/GHW-December.git
- https:
- Check out the
Dockerfile
to understand what's happening - Login to your docker account in your shell
docker login
- Run
docker build -t <docker_username>/<image_name>:<version_number> .
- It shoudl look like this:
β GHW-December git:(main) β docker build -t ashwinexe/ghw:1.0 .
Sending build context to Docker daemon 9.639MB
Step 1/6 : FROM node:current-slim
---> b131f467b9ea
Step 2/6 : LABEL MAINTAINER="kumarashwin2603@gmail.com"
---> Running in ad644f733bb0
Removing intermediate container ad644f733bb0
---> 80536b85f226
Step 3/6 : COPY . /src
---> a0d5b1092b14
Step 4/6 : RUN cd /src; npm install
---> Running in 69961af002d6
up to date, audited 97 packages in 5s
12 packages are looking for funding
run `npm fund` for details
Successfully built 1f2bfa5b0245
Successfully tagged ashwinexe/ghw:1.0
Notice the "." in the end is crucial, it tells docker that all the files in the local directory get compressed and sent to the Docker daemon.
- Run your docker image with port exposed:
docker run -p 8080:8080 ashwinexe/ghw:1.0
- Check localhost:8080 in your browser
Fact: 8080:8080 means any request coming for port 8080 will be forwarded to service running on port 8080 inside your container. simply put
docker run -p Port for Outside World: Actual Port of service in container ashwinexe/ghw:1.0
- Push your image to dockerhub
docker push <username>/<image>:<version>
- for eg: in my case it'd be
docker pull ashwinexe/ghw:1.0
- for eg: in my case it'd be
You can use my deployed version if you wish so: docker pull ashiwnexe/ghw:1.0
There are several ways to run kubernetes locally on your machine. Docker Desktop
is the easier way to get started
Still curious? Check out Kind, minikube and kubeadm which are also popular choice to run kubernetes locally
- Run Docker Desktop -> Settings -> Kubernetes -> Toggle
Enable Kubernetes
-> Check Kubernetes status at the bottom
- Open command terminal and run
kubectl get nodes
your output should look like:
kubectl get nodes
NAME STATUS ROLES AGE VERSION
docker-desktop Ready control-plane 5d11h v1.25.2
Hurray! You got your own Kubernetes cluster running! π₯³
So you containerized a Node.js web application into a container image and stored it on Docker Hub. You're about to deploy that application to your cluster inside a Kubernetes Pod.
kubectl apply -f pod.yaml
//applies Pod configurationkubectl apply -f service-local.yaml
//applies Service configuration to expose port locally- Verify service
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9d
svc-local NodePort 10.96.122.250 <none> 8080:30000/TCP 7h33m
Check the output at localhost:30000 (or where NodePort is exposed in your service-local.yaml
file)