Skip to content

same7ammar/kube-nodejs-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About

Simple Nodejs app to deploy it to Kubernetes cluster or Docker container.

requirements

  1. Docker Installed.
  2. Rancher Desktop - https://rancherdesktop.io .
  3. kubectl if not installed .

quick install .

$ kubectl apply -f https://raw.githubusercontent.com/same7ammar/kube-nodejs-sample/main/kubernetes/deployment.yaml
$ kubectl apply -f https://raw.githubusercontent.com/same7ammar/kube-nodejs-sample/main/kubernetes/kubernetes/service.yaml

$ kubectl get svc
NAME             TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
nodejs-web-app   LoadBalancer   10.43.240.254   172.17.152.146   3000:30043/TCP   7s
to test service use  curl http://EXTERNAL-IP:PORT
$ curl http://172.17.152.146 
Hello World

Build your own docker image and push it to Docker hub.

  1. clone git repo to your local machine.
git clone https://github.com/same7ammar/kube-nodejs-sample.git
  1. Build your docker image :
$ cd app
$ docker build . -t <your username>/nodejs-sample-k8s
$ docker run -p 3000:3000-d <your username>/nodejs-sample-k8s
# Get container ID
$ docker ps
$ curl curl http://localhost:3000
Hello World
  1. Upload image to your docker-Hub Account :
$ docker login -u same7ammar  --password-stdin 
Login Succeeded
$ docker push <your username>/nodejs-sample-k8s
Using default tag: latest
The push refers to repository [docker.io/same7ammar/node-web-app-k8s]
.....
latest: digest: sha256:fa5dd972a9cd1555f3cb4a837aaf5d78bc862fa0053474d9f64f3e7d3eb15ae2 size: 3048

Deploy to Kubernetes - Rancher Desktop or other types.

  1. create a deployment .
$ kubectl apply -f kubernetes/deployment.yaml 
deployment.apps/nodejs-web-app created

$  kubectl get pods
NAME                              READY   STATUS              RESTARTS   AGE
nodejs-web-app-6fdf6d4f54-m4mgn   0/1     ContainerCreating   0          10s

$ kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
nodejs-web-app-6fdf6d4f54-m4mgn   1/1     Running   0          2m18s
  1. create a service to expose this app .
$ kubectl apply -f kubernetes/service.yaml
service/nodejs-web-app created

$ kubectl get svc
NAME             TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
nodejs-web-app   LoadBalancer   10.43.240.254   172.17.152.146   3000:30043/TCP   7s
to test service use  curl http://EXTERNAL-IP:PORT
$ curl http://172.17.152.146 
Hello World

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published