Giter Club home page Giter Club logo

spring-k8s-replicaset's Introduction

spring-k8s-replicaset

SpringBoot to Kubernetes with ReplicaSet.

image

Kubernetes Master Components: Etcd, API Server, Controller Manager, and Scheduler

etcd is a distributed reliable key-value store for the most critical data of a distributed system, with a focus on being:

  • Simple: well-defined, user-facing API (gRPC)
  • Secure: automatic TLS with optional client cert authentication
  • Fast: benchmarked 10,000 writes/sec
  • Reliable: properly distributed using Raft. Etcd is written in Go and uses the Raft consensus algorithm to manage a highly-available replicated log. Raft is a consensus algorithm designed as an alternative to Paxos. The Consensus problem involves multiple servers agreeing on values; a common problem that arises in the context of replicated state machines. Raft defines three different roles (Leader, Follower, and Candidate) and achieves consensus via an elected leader. For further information, please read the (Raft paper)[https://raft.github.io/raft.pdf].

##Etcdctl[https://github.com/etcd-io/etcd/tree/main/etcdctl] is the command-line interface tool written in Go that allows manipulating an etcd cluster. It can be used to perform a variety of actions, such as:

  • Set, update and remove keys.
  • Verify the cluster health.
  • Add or remove etcd nodes.
  • Generating database snapshots.
  • You can play online with a 5-node etcd cluster at http://play.etcd.io.

Scheduler

The Scheduler watches for unscheduled pods and binds them to nodes via the /binding pod subresource API, according to the availability of the requested resourcesThe Scheduler watches for unscheduled pods and binds them to nodes via the /binding pod subresource API, according to the availability of the requested resources. Once the pod has a node assigned, the regular behavior of the Kubelet is triggered and the pod and its containers are created.

Controller Manager

The Kubernetes Controller Manager is a daemon that embeds the core control loops (also known as “controllers”) shipped with Kubernetes. Basically, a controller watches the state of the cluster through the API Server watch feature and, when it gets notified, it makes the necessary changes attempting to move the current state towards the desired state.

API Server

When you interact with your Kubernetes cluster using the kubectl command-line interface, you are actually communicating with the master API Server component.

image

image

  1. kubectl writes to the API Server.
  2. API Server validates the request and persists it to etcd.
  3. etcd notifies back the API Server.
  4. API Server invokes the Scheduler.
  5. Scheduler decides where to run the pod on and return that to the API Server.
  6. API Server persists it to etcd.
  7. etcd notifies back the API Server.
  8. API Server invokes the Kubelet in the corresponding node.
  9. Kubelet talks to the Docker daemon using the API over the Docker socket to create the container.
  10. Kubelet updates the pod status to the API Server.
  11. API Server persists the new state in etcd.

Build the project

Build a Docker Image

1- Docker cmd build <Preferred>

 docker build -t ahmedalsalih/spring-k8s:v2.2 .

or

2- Maven build

./mvnw spring-boot:build-image

Run the image FOR TEST ONLY

docker run -p 9090:8080 ahmedalsalih/spring-k8s:v2.2

Push the image to Docker Hub

Push image

Docker Hub

Run Kubernetes

run git bash As Admin the type:

minikube start

image

Create deployment

kubectl create deployment springk8sapp --image=ahmedalsalih/spring-k8s:v2.2

image

deployment and pod created as well.

k8s-level

kubectl

kubectl get pods
kubectl get replicaset
kubectl describe pod springk8sapp-64c6ff74cd-86hpv

Success deployment creating image

Dashboard

minikube dashboard

Scale a resource / Replicaset

kubectl scale -n default deployment springk8sapp --replicas=3

Update deployment

kubectl apply -f <spec.yaml>

Create deployment from form

image

-----------------==========-------------------Delete---------------------==============----------------

Delete all deployment

kubectl delete --all deployments

Checking All three comends below should give No resources found in default namespace.

kubectl get pods
kubectl get deployment
kubectl get replicaset

Create deployment YAML file

kubectl apply -f deployment.yaml
kubectl get deployment -o wide

image

Query by Selctor

kubectl get pods --selector app=springk8s-app

image ###############################################################################################################

Log

Checking the pod log using kubectl logs <Pod name>

kubectl logs springk8s-app-deployment-df7f649b7-88zg9

Quick test creat deployment & Expose

kubectl create deployment springk8sapp --image=ahmedalsalih/spring-k8s:v2.2

Expose the application

-type=NodePort and --type=LoadBalancer

kubectl expose deployment springk8sapps --type=NodePort --port=8080

LoadBalancer

minikube tunnel
kubectl expose deployment springk8s-app-deployment --type=LoadBalancer --port=8080

or:

kubectl expose deployment springk8s-app-deployment --name=springk8s-service --port=80 --target-port=8080 --type=LoadBalancer
kubectl get service

Delete service

Display the service wide:

kubectl get service -o wide

kubectl delete svc

kubectl delete svc springk8s-app-deployment

Delete all of the minikube clusters:

minikube delete --all

spring-k8s-replicaset's People

Contributors

ahmed82 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

spring-k8s-replicaset's Issues

[ValidationError(Deployment.spec.selector): unknown field "app" in io.k8s.apimachinery.pkg.apis.m

$ kubectl apply -f deployment.yaml
error: error validating "deployment.yaml": error validating data: [ValidationError(Deployment.spec.selector): unknown field "app" in io.k8s.apimachinery.pkg.apis.m
eta.v1.LabelSelector, ValidationError(Deployment.spec.template): unknown field "labels" in io.k8s.api.core.v1.PodTemplateSpec, ValidationError(Deployment.spec.temp
late): unknown field "ports" in io.k8s.api.core.v1.PodTemplateSpec, ValidationError(Deployment.spec.template.spec): unknown field "image" in io.k8s.api.core.v1.Pod
Spec]; if you choose to ignore these errors, turn validation off with --validate=false

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.