Skip to content

Deepak-147/Microservices-SpringBoot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices using Spring Boot (with Google Cloud)

Table of contents:

  1. Google Kubernetes Engine (GKE)
  2. How GKE works
  3. Basic terminology
  4. Creating Kubernetes Cluster
  5. Connecting to a Kubernetes Cluster
    1. Connecting using Google Cloud Shell
    2. Interacting with cluster using Kubectl (Kubernetes Controller, command line interface)
    3. Interacting with the cluster using local machine
    4. Deployments
    5. Configmaps

1. Google Kubernetes Engine (GKE)

Google Kubernetes Engine (GKE), a managed Kubernetes service that you can use to deploy and operate containerized applications at scale using Google's infrastructure.

2. How GKE works

A GKE environment consists of nodes, which are Compute Engine virtual machines (VMs), that are grouped together to form a cluster. You package your apps (also called workloads) into containers. You deploy sets of containers as Pods to your nodes. You use the Kubernetes API to interact with your workloads, including administering, scaling, and monitoring.

3. Basic terminology

  • Node is a virtual server (server on cloud)

  • Kubernetes manages 1000s of nodes. It has master nodes (or manager) to manage the worker nodes.  The combination of master nodes and worker nodes forms a cluster

  • Containers package an application so it can easily be deployed to run in its own isolated environment. Containers are run on Kubernetes clusters. Containers are an isolated environment to run any code.

  • Pod is the smallest deployable unit. Pod is a collection of containers that can run on a host. A Kubernetes node can contain multiple Pods, and a Pod can contain multiple containers

  • ReplicaSet ensures that a specified number of pod replicas are running at any given time.

  • Service allows your application to receive traffic through a permanent address. It provides a constant frontend url for our consumers, irrespective of the changes happening in backend url due to pod changes. Load Balancer is a type of service.

    Terms

4. Creating Kubernetes Cluster

Create Cluster


Create Cluster2

5. Connecting to a Kubernetes Cluster

Connect Cluster

gcloud container clusters get-credentials <cluster-name> --region <region-name> --project <project-id>

1. Connecting using Google Cloud Shell

Connect Cluster using Cloud shell

2. Interacting with cluster using Kubectl (Kubernetes Controller, command line interface)

  • 1. Check version:

    kubectl version

    kubectl version

  • 2. Create Deployment:

    kubectl create deployment <deployment name> --image=<image name>

    Create deployment

  • 3. Expose Deployment:

    kubectl expose deployment <deployment name> --type=<type> --port=<port name>

    Expose deployment

  • 4. View Workloads:

    Workloads


    Workloads2

  • 5. Verify Endpoints:

    verify endpoints

  • 6. get:

    kubectl get <type>

    Where type can be event(s), pod(s), replicaset(s), deployment(s), service(s), all

    with options: kubectl get <type> -o wide

    sort events by creation time: kubectl get events --sort-by=.metadata.creationTimestamp

    Get command

  • 7. explain:

    kubectl explain <type>

    Where type can be event(s), pod(s), replicaset(s), deployment(s), service(s)

  • 8. describe:

    kubectl describe pod <pod-name>

  • 9. delete:

    kubectl delete pods <pod name>

    Deletes everything (Deployments, services, pods, replicaset ...etc) about the given app-name

    kubectl delete all -l app=<app-name>

    Delete

    Even after deleting the pod, the replicaset made sure to have sufficient number of pods running. So it sprung up another pod.

  • 10. scale deployment:

    kubectl scale deployment <deployment name> --replicas=<number of replicas>

    Scale

3. Interacting with the cluster using local machine

  • 1. Installing gcloud CLI

    Installation Guide

    gloud init

    gcloud init

  • 2. Installing kubectl

    Installation Guide

    kubectl version --client

    kubectl version

    Connect to the cluster and issue the command kubectl version to check both client and server versions

    kubectl version

4. Deployments

  • 1. Creating deployment manually

    • 1.1 Deploying currency exchange microservice

      • kubectl create deployment currency-exchange --image=ldeepak/udemy-microservices-currency-exchange-service:0.0.11-SNAPSHOT

      • kubectl expose deployment currency-exchange --type=LoadBalancer --port=8000

      • kubectl get svc, to get the External IP of the service.

      • Execute the request on postman: http://External IP:8000/currency-exchange/from/USD/to/INR

      verify endpoints

    • 1.2 Deploying currency conversion microservice

      • kubectl create deployment currency-conversion --image=ldeepak/udemy-microservices-currency-conversion-service:0.0.11-SNAPSHOT

      • kubectl expose deployment currency-conversion --type=LoadBalancer --port=8100

      • kubectl get svc, to get the External IP of the service.

      • Execute the request on postman: http://External IP:8100/currency-conversion-feign/from/USD/to/INR/quantity/10

      currency conversion

  • 2. Creating deployment using declarative YAML configuration file

    • Create your deployment file
    • kubectl apply -f <deployment-file-name.yaml>
    • kubectl get all, to check the deployment
    • kubectl get svc, to get the External IP of the service
    • Execute the request on postman: http://External IP:8000/currency-exchange/from/USD/to/INR
  • 3. Check difference in deployment file

    kubectl diff -f <deployment-file-name.yaml>

  • 4. Check deployment history

    kubectl rollout history deployment <app_name>

5. Configmaps

  • 1. Create configmap

    kubectl create configmap <configmap_name> --from-literal=<key>=<value>

    configmap

  • 2. Get config maps

    kubectl get configmap

  • 3. Get yaml configuration of the configmap into a file

    kubectl get configmap <configmap_name> -o yaml >> <file_name.yaml>

About

Repository created while learning Spring Microservices

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages