├── .gitignore ├── Badge └── Blahajnetes.png ├── Dockerfile ├── pod.yaml ├── service-local.yaml ├── app.js ├── index.html ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Badge/Blahajnetes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwinexe/GHW-December/HEAD/Badge/Blahajnetes.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:current-slim 2 | 3 | LABEL MAINTAINER="kumarashwin2603@gmail.com" 4 | 5 | COPY . /src 6 | 7 | RUN cd /src; npm install 8 | 9 | EXPOSE 8080 10 | 11 | CMD cd /src; node ./app.js -------------------------------------------------------------------------------- /pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: first-pod 5 | labels: 6 | event: ghw 7 | spec: 8 | containers: 9 | - name: node 10 | image: ashwinexe/ghw:1.0 11 | ports: 12 | - containerPort: 8080 -------------------------------------------------------------------------------- /service-local.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: svc-local 5 | spec: 6 | type: NodePort 7 | ports: 8 | - port: 8080 9 | protocol: TCP 10 | targetPort: 8080 11 | nodePort: 30000 12 | selector: 13 | event: ghw -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const path = require('path'); 3 | 4 | const app = express(); 5 | const port = process.env.PORT || 8080; 6 | 7 | // File will go here 8 | app.get('/', function(req, res){ 9 | res.sendFile(path.join(__dirname, '/index.html')); 10 | }); 11 | 12 | app.listen(port); 13 | console.log('Server started at http://localhost:' + port); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

11 | Hello GHW! 12 |

13 |

This is server running on Kubernetes!

14 |

Don't forget to Check In!

15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ghw-december", 3 | "version": "1.0.0", 4 | "description": "packages for my website", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/ashwinexe/GHW-December.git" 12 | }, 13 | "author": "ashwinexe", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/ashwinexe/GHW-December/issues" 17 | }, 18 | "homepage": "https://github.com/ashwinexe/GHW-December#readme", 19 | "dependencies": { 20 | "express": "^4.18.2", 21 | "pug": "^3.0.2" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ashwin Kumar Uppala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GHW-December 🎅🎅 2 | Notes and resources for GHW December stream on **Deploying your first Kubernetes Cluster** 3 | 4 | Watch the recording of all three parts here: 5 | - [Part 1](https://www.youtube.com/watch?v=nRe0GqRkah4&t=4133s&pp=ygU5R2xvYmFsIEhhY2sgV2VlazogRGVwbG95aW5nIFlvdXIgZmlyc3QgS3ViZXJuZXRlcyBDbHVzdGVy ) 6 | - [Part 2](https://www.youtube.com/live/nRe0GqRkah4?feature=share) 7 | - [Part 3](https://www.youtube.com/live/N4kgxRERAZI?feature=share) 8 | 9 | ## Setting up 🖥️ 10 | 1. Install [Git](https://git-scm.com/) 11 | 2. Install [Node](https://nodejs.org/en/download/) 12 | 3. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) 13 | 4. Create an account on [Docker Hub](https://hub.docker.com/) 14 | 1. Login to Docker Desktop with your docker account 15 | 2. Login to Docker CLI `docker login` ([more info](https://docs.docker.com/engine/reference/commandline/login/)) 16 | 5. Clone this repo 17 | 1. https: `https://github.com/ashwinexe/GHW-December.git` 18 | 2. ssh: `git@github.com:ashwinexe/GHW-December.git` 19 | 20 | ## Conterize your app 🚀 21 | 1. Check out the `Dockerfile` to understand what's happening 22 | 2. Login to your docker account in your shell `docker login` 23 | 3. Run `docker build -t /: .` 24 | 4. It shoudl look like this: 25 | ``` 26 | ➜ GHW-December git:(main) ✗ docker build -t ashwinexe/ghw:1.0 . 27 | Sending build context to Docker daemon 9.639MB 28 | Step 1/6 : FROM node:current-slim 29 | ---> b131f467b9ea 30 | Step 2/6 : LABEL MAINTAINER="kumarashwin2603@gmail.com" 31 | ---> Running in ad644f733bb0 32 | Removing intermediate container ad644f733bb0 33 | ---> 80536b85f226 34 | Step 3/6 : COPY . /src 35 | ---> a0d5b1092b14 36 | Step 4/6 : RUN cd /src; npm install 37 | ---> Running in 69961af002d6 38 | 39 | up to date, audited 97 packages in 5s 40 | 41 | 12 packages are looking for funding 42 | run `npm fund` for details 43 | Successfully built 1f2bfa5b0245 44 | Successfully tagged ashwinexe/ghw:1.0 45 | ``` 46 | 47 | >> 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. 48 | 49 | 5. Run your docker image with port exposed: 50 | 1. `docker run -p 8080:8080 ashwinexe/ghw:1.0` 51 | 2. Check localhost:8080 in your browser 52 | 53 | >> Fact: 8080:8080 means any request coming for port 8080 will be forwarded to service running on port 8080 inside your container. simply put 54 | `docker run -p Port for Outside World: Actual Port of service in container ashwinexe/ghw:1.0` 55 | 56 | 6. Push your image to dockerhub `docker push /:` 57 | 1. for eg: in my case it'd be `docker pull ashwinexe/ghw:1.0` 58 | 59 | You can use my deployed version if you wish so: `docker pull ashiwnexe/ghw:1.0` 60 | 61 | ## Enable Kuberenetes 🕹️ 62 | There are several ways to run kubernetes locally on your machine. `Docker Desktop` is the easier way to get started 63 | 64 | >> Still curious? Check out Kind, minikube and kubeadm which are also popular choice to run kubernetes locally 65 | 66 | - Run Docker Desktop -> Settings -> Kubernetes -> Toggle `Enable Kubernetes` -> Check Kubernetes status at the bottom 67 | 68 | ![](https://i.imgur.com/oDYxGti.png) 69 | 70 | - Open command terminal and run `kubectl get nodes` your output should look like: 71 | ``` 72 | kubectl get nodes 73 | NAME STATUS ROLES AGE VERSION 74 | docker-desktop Ready control-plane 5d11h v1.25.2 75 | ``` 76 | 77 | Hurray! You got your own Kubernetes cluster running! 🥳 78 | 79 | *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.* 80 | 81 | ## Configure Kubenetes 82 | - `kubectl apply -f pod.yaml` //applies Pod configuration 83 | - `kubectl apply -f service-local.yaml` //applies Service configuration to expose port locally 84 | - Verify service 85 | ``` 86 | $ kubectl get svc 87 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 88 | kubernetes ClusterIP 10.96.0.1 443/TCP 9d 89 | svc-local NodePort 10.96.122.250 8080:30000/TCP 7h33m 90 | ``` 91 | Check the output at **localhost:30000** (or where NodePort is exposed in your `service-local.yaml` file) 92 | 93 | 94 | ## Extra Resources 💃 95 | - [Workshop Slides](https://docs.google.com/presentation/d/14xpFkT-ZIIsl-HyU1WMxmrKKzsK9WGdigfn0E72bQaU/edit?usp=sharing) 96 | - [Containerzie a node app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/) 97 | - [Hosting a simple static app using Express](https://www.digitalocean.com/community/tutorials/use-expressjs-to-deliver-html-files) 98 | - [ExpressJS tutorial](https://www.freecodecamp.org/news/express-explained-with-examples-installation-routing-middleware-and-more/#:~:text=Both%20req%20and%20res%20are,it%20gets%20an%20HTTP%20request.) 99 | --------------------------------------------------------------------------------