Coder Social home page Coder Social logo

erdharmesh / kubernetes-zerotohero Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 29 KB

In this document, I will show you the from the basic, how to write a simple app, build it, containerize it, deploy in kubernetes and expose to external world using Kubernetes services.

kubernetes-zerotohero's Introduction

Kubernetes-zeroToHero

In this document, I will show you the from the basic, how to write a simple app, build it, containerize it, deploy in kubernetes and expose to external world using Kubernetes services.

prerequisite

install minikube, docker, node,

check minikube status

  1. minikube status minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured

build one application

  1. we are going with angular application.
  2. check the version or install it.

HTML website simple one

  1. vi index.html

     <!DOCTYPE html>
     <html>
     <head>
     <title>HTML Website</title>
     </head>
     <body>
     
     <h1>Kubernetes Demo</h1>
     <p>Here you will learn kubernetes.</p>
     
     </body>
     </html>
    
  2. vi Dockerfile FROM python COPY index.html index.html EXPOSE 6100 CMD ["python", "-m","http.server","6100"]

  3. docker build .

  4. docker images

  5. docker run -it -p 6100:6100 48094f98be49

  6. HTTP://localhost:6100

  7. docker tag 48094f98be49 docker.io/dharmesh09/html-web:v1

  8. docker push docker.io/dharmesh09/html-web:v1

  9. now with docker your html application is working well.

  10. with kubernetes let's try

  11. For kubernetes required

    1. deployment.yaml
    2. service.yaml
  12. vi deployment.yaml

apiVersion: apps/v1 kind: Deployment metadata: name: html-web labels: app: html-web spec: replicas: 1 selector: matchLabels: app: html-web template: metadata: labels: app: html-web spec: containers: - name: html-web image: docker.io/dharmesh09/html-web:v1 ports: - containerPort: 6100

  1. kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES html-web-799dcc499f-4ckt9 1/1 Running 0 5m20s 10.244.0.9 minikube

  2. check with this ip pod can communicate or not.

  3. minikube ssh

  4. curl -L 10.244.0.9:6100 [here you will see your HTML file] docker@minikube:~$ curl -L 10.244.0.9:6100 <title>HTML Website</title>

    <h1>Kubernetes Demo</h1>
    <p>Here you will learn kubernetes.</p>
    
    </body>
    </html>
    
  5. here when your pod is killed or recreated that time it's assigned with new ip address. so, here we need service.yaml becoz it's ip is not chnage that's advantage of it.

  6. vi service.yaml apiVersion: v1 kind: Service metadata: name: html-web spec: type: NodePort selector: app: html-web ports:

    • protocol: TCP port: 80 targetPort: 6100 nodePort: 31080
  7. here nodePort size between: 30k to 32k 20.kubectl apply -f service.yaml

  8. kubectl get svc -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR html-web NodePort 10.109.119.202 80:31080/TCP 8s app=html-web kubernetes ClusterIP 10.96.0.1 443/TCP 23h

  9. again you can check with now cluster ip your ssh will comunicate or not.

  10. minikube ssh

  11. docker@minikube:~$ curl -L 192.168.49.2:31080 <title>HTML Website</title>

    <h1>Kubernetes Demo</h1>
    <p>Here you will learn kubernetes.</p>
    
    </body>
    </html>
    
  12. now your pod is 100 time recreated you will get response with this ip's only. that's advantage of k8s.

  13. now this ip is only communicate only internal cluster communication.

  14. i want to access it on my crome browser.

  15. it happened by ingress only.

  16. vi ingress.yaml

apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-wildcard-host spec: rules:

  • host: html-web.com http: paths:
    • pathType: Prefix path: "/" backend: service: name: html-web port: number: 80
  1. kubectl apply -f ingress.yaml
  2. kubectl get ingress -n default NAME CLASS HOSTS ADDRESS PORTS AGE ingress-wildcard-host html-web 192.168.49.2 80 21h

done

● ● ● ●

kubernetes-zerotohero's People

Contributors

erdharmesh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.