Giter Site home page Giter Site logo

springbootk8s's Introduction

minikube start

eval $(minikube docker-env) 

docker build -t springboot-k8s:1.0 .

kubectl create deployment springboot-k8s --image=springboot-k8s:1.0 --port 8080 
deployment.apps/springboot-k8s created

kubectl get deployments                  
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
springboot-k8s   1/1     1            1           3s

kubectl get pods                     
NAME                              READY   STATUS    RESTARTS   AGE
springboot-k8s-6f8ddcbb45-wf7kz   1/1     Running   0          11m

kubectl expose deployment springboot-k8s --type=NodePort
service/springboot-k8s exposed

kubectl get services                 
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP          23h
springboot-k8s   NodePort    10.109.74.102   <none>        8080:30436/TCP   2m3s

minikube ip
192.168.49.2

http://192.168.49.2:30436/greeting

kubectl get nodes -o wide 
NAME       STATUS   ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
minikube   Ready    control-plane   23h   v1.26.1   192.168.49.2   <none>        Ubuntu 20.04.5 LTS   5.15.49-linuxkit   docker://20.10.23

kubectl get nodes -o wide            
NAME       STATUS   ROLES           AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
minikube   Ready    control-plane   23h   v1.26.1   192.168.49.2   <none>        Ubuntu 20.04.5 LTS   5.15.49-linuxkit   docker://20.10.23

kubectl logs springboot-k8s-6f8ddcbb45-wf7kz                                 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.6.RELEASE)

2023-02-03 19:50:50.646  INFO 1 --- [           main] c.s.k.s.SpringbootKubernetesApplication  : Starting SpringbootKubernetesApplication v0.0.1-SNAPSHOT on springboot-k8s-6f8ddcbb45-wf7kz with PID 1 (/app.jar started by root in /)
2023-02-03 19:50:50.649  INFO 1 --- [           main] c.s.k.s.SpringbootKubernetesApplication  : No active profile set, falling back to default profiles: default
2023-02-03 19:50:52.378  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-02-03 19:50:52.429  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-02-03 19:50:52.430  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2023-02-03 19:50:52.478  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-02-03 19:50:52.478  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1714 ms
2023-02-03 19:50:52.765  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2023-02-03 19:50:53.065  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-02-03 19:50:53.069  INFO 1 --- [           main] c.s.k.s.SpringbootKubernetesApplication  : Started SpringbootKubernetesApplication in 3.337 seconds (JVM running for 3.89)

kubectl get svc

kubectl pods -o wide               
NAME                              READY   STATUS    RESTARTS   AGE     IP            NODE       NOMINATED NODE   READINESS GATES
springboot-k8s-6f8ddcbb45-gwbmx   1/1     Running   0          5m45s   10.244.0.68   minikube   <none>           <none>

kubectl scale --replicas=3 deployment/springboot-k8s

kubectl get pods -o wide                              
NAME                              READY   STATUS    RESTARTS   AGE     IP            NODE       NOMINATED NODE   READINESS GATES
springboot-k8s-6f8ddcbb45-dcx9v   1/1     Running   0          4s      10.244.0.69   minikube   <none>           <none>
springboot-k8s-6f8ddcbb45-gq4p5   1/1     Running   0          4s      10.244.0.70   minikube   <none>           <none>
springboot-k8s-6f8ddcbb45-gwbmx   1/1     Running   0          9m21s   10.244.0.68   minikube   <none>           <none>

minikube service springboot-k8s
|-----------|----------------|-------------|---------------------------|
| NAMESPACE |      NAME      | TARGET PORT |            URL            |
|-----------|----------------|-------------|---------------------------|
| default   | springboot-k8s |        8080 | http://192.168.49.2:30794 |
|-----------|----------------|-------------|---------------------------|
๐Ÿƒ  Starting tunnel for service springboot-k8s.
|-----------|----------------|-------------|------------------------|
| NAMESPACE |      NAME      | TARGET PORT |          URL           |
|-----------|----------------|-------------|------------------------|
| default   | springboot-k8s |             | http://127.0.0.1:50941 |
|-----------|----------------|-------------|------------------------|
๐ŸŽ‰  Opening service default/springboot-k8s in default browser...
โ—  Because you are using a Docker driver on darwin, the terminal needs to be open to run it.


kubectl get deployments
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
springboot-k8s   3/3     3            3           13m

kubectl get pods       
NAME                              READY   STATUS    RESTARTS   AGE
springboot-k8s-6f8ddcbb45-dcx9v   1/1     Running   0          5m21s
springboot-k8s-6f8ddcbb45-gq4p5   1/1     Running   0          5m21s
springboot-k8s-6f8ddcbb45-gwbmx   1/1     Running   0          14m

// to check replicas
kubectl get rs 
NAME                        DESIRED   CURRENT   READY   AGE
springboot-k8s-6f8ddcbb45   3         3         3       16m

minikube dashboard
๐Ÿค”  Verifying dashboard health ...
๐Ÿš€  Launching proxy ...
๐Ÿค”  Verifying proxy health ...
๐ŸŽ‰  Opening http://127.0.0.1:51009/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...


// when it reached 50% autoscale container
kubectl autoscale deployment springboot-k8s --cpu-percent=50 --min=1 --max=10
horizontalpodautoscaler.autoscaling/springboot-k8s autoscaled

kubectl get hpa
// hpa => horizontalpodautoscaler

kubectl get hpa
NAME             REFERENCE                   TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
springboot-k8s   Deployment/springboot-k8s   <unknown>/50%   1         10        3          46m

kubectl get deployments
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
springboot-k8s   3/3     3            3           27m

kubectl get deployments -o wide
NAME             READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS       IMAGES               SELECTOR
springboot-k8s   3/3     3            3           27m   springboot-k8s   springboot-k8s:1.0   app=springboot-k8s

Process to update image:

docker build -t springboot-k8s:2.0 .

kubectl set image deployment springboot-k8s springboot-k8s=springboot-k8s:2.0

kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
springboot-k8s-6f8ddcbb45-dcx9v   1/1     Running   0          22m
springboot-k8s-6f8ddcbb45-gq4p5   1/1     Running   0          22m
springboot-k8s-6f8ddcbb45-gwbmx   1/1     Running   0          31m

kubectl get deployments
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
springboot-k8s   3/3     3            3           31m

kubectl get services   
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes       ClusterIP   10.96.0.1      <none>        443/TCP          24h
springboot-k8s   NodePort    10.103.28.69   <none>        8080:30794/TCP   32m

kubectl describe rs

kubectl describe deployments

kubectl delete deploy springboot-k8s
kubectl delete svc springboot-k8s
kubectl delete pod springboot-k8s

kubectl apply -f deployment.yml
kubectl apply -f service.yml

kubectl apply -f deployment.yml
deployment.apps/springboot-k8s created

kubectl apply -f service.yml
service/springboot-k8s created

minikube service springboot-k8s
http://127.0.0.1:51293/greeting

kubectl delete deploy springboot-k8s
kubectl delete svc springboot-k8s
kubectl delete pod springboot-k8s

docker rm $(docker ps -a -q) -f
docker rmi $(docker images -a -q) -f
docker ps -a
docker images -a
Deployment is responsible to run a set of pods and service gives network access to these pods

Screenshot 2023-02-04 at 12 56 13 AM

Screenshot 2023-02-04 at 12 57 04 AM

Screenshot 2023-02-04 at 1 02 28 AM

Screenshot 2023-02-04 at 1 55 15 AM

Screenshot 2023-02-04 at 1 55 32 AM

Screenshot 2023-02-04 at 1 59 36 AM

Screenshot 2023-02-04 at 2 00 54 AM

Screenshot 2023-02-04 at 2 01 28 AM

Screenshot 2023-02-04 at 2 01 50 AM

Screenshot 2023-02-04 at 2 02 25 AM

Screenshot 2023-02-04 at 2 02 56 AM

Screenshot 2023-02-04 at 2 03 18 AM

Screenshot 2023-02-04 at 2 03 43 AM

Screenshot 2023-02-04 at 2 04 15 AM

Screenshot 2023-02-04 at 2 04 53 AM

Screenshot 2023-02-04 at 2 05 22 AM

Screenshot 2023-02-04 at 2 13 20 AM

Screenshot 2023-02-04 at 2 15 52 AM

Screenshot 2023-02-04 at 2 16 54 AM

Screenshot 2023-02-04 at 2 19 32 AM

Screenshot 2023-02-04 at 2 21 19 AM

Screenshot 2023-02-04 at 2 25 01 AM

/*
kubectl run springboot-k8s --image=springboot-k8s:1.0 --port 8080 --image-pull-policy=Never
pod/springboot-k8s created
*/

springbootk8s's People

Contributors

saiashish9 avatar

Stargazers

 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.