https://github.com/deepak-147/microservices-springboot
Repository created while learning Spring Microservices
https://github.com/deepak-147/microservices-springboot
docker google-cloud-platform kubernetes microservice spring-boot spring-cloud
Last synced: 4 months ago
JSON representation
Repository created while learning Spring Microservices
- Host: GitHub
- URL: https://github.com/deepak-147/microservices-springboot
- Owner: Deepak-147
- Created: 2022-01-11T05:30:37.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-08T14:38:07.000Z (almost 2 years ago)
- Last Synced: 2025-02-23T07:24:15.198Z (about 1 year ago)
- Topics: docker, google-cloud-platform, kubernetes, microservice, spring-boot, spring-cloud
- Language: Java
- Homepage:
- Size: 10.6 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Microservices using Spring Boot (with Google Cloud)
**Table of contents:**
1. [Google Kubernetes Engine (GKE)](#gke)
2. [How GKE works](#how-gke)
3. [Basic terminology](#basics)
4. [Creating Kubernetes Cluster](#create-cluster)
5. [Connecting to a Kubernetes Cluster](#connect-cluster)
1. [Connecting using Google Cloud Shell](#connect-gcloud-shell)
2. [Interacting with cluster using Kubectl (Kubernetes Controller, command line interface)](#kubectl)
3. [Interacting with the cluster using local machine](#local)
4. [Deployments](#deployment)
5. [Configmaps](#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.

## 4. Creating Kubernetes Cluster


## 5. Connecting to a Kubernetes Cluster

```gcloud container clusters get-credentials --region --project ```
### 1. Connecting using Google Cloud Shell

### 2. Interacting with cluster using Kubectl (Kubernetes Controller, command line interface)
- **1. Check version:**
```kubectl version```

- **2. Create Deployment:**
```kubectl create deployment --image=```

- **3. Expose Deployment:**
```kubectl expose deployment --type= --port=```

- **4. View Workloads:**


- **5. Verify Endpoints:**

- **6. get:**
```kubectl get ```
Where type can be event(s), pod(s), replicaset(s), deployment(s), service(s), all
with options:
```kubectl get -o wide```
sort events by creation time:
```kubectl get events --sort-by=.metadata.creationTimestamp```

- **7. explain:**
```kubectl explain ```
Where type can be event(s), pod(s), replicaset(s), deployment(s), service(s)
- **8. describe:**
```kubectl describe pod ```
- **9. delete:**
```kubectl delete pods ```
Deletes everything (Deployments, services, pods, replicaset ...etc) about the given app-name
```kubectl delete all -l app=```

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 --replicas=```

### 3. Interacting with the cluster using local machine
- **1. Installing gcloud CLI**
[Installation Guide](https://cloud.google.com/sdk/docs/install)
```gloud init```

- **2. Installing kubectl**
[Installation Guide](https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/)
```kubectl version --client```

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

### 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

- **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

- **2. Creating deployment using declarative YAML configuration file**
- Create your deployment file
- ```kubectl apply -f ```
- ```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 ```
- **4. Check deployment history**
```kubectl rollout history deployment ```
### 5. Configmaps
- **1. Create configmap**
```kubectl create configmap --from-literal==```

- **2. Get config maps**
```kubectl get configmap```
- **3. Get yaml configuration of the configmap into a file**
```kubectl get configmap -o yaml >> ```