Skip to content

Commit

Permalink
Microservices: add hands on script (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq committed May 11, 2024
1 parent 5472a76 commit 8b79ead
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,20 @@ We cover a wide range of DevOps topics in our content library, explore them unde
<td>Architecture</td>
<td><a href="./topics/architecture/">architecture</a></td>
<td>📖 <a href="https://github.com/tungbq/devops-basic/blob/main/topics/architecture/README.md">architecture/README.md</a></td>
<td>⏩ coming-soon</td>
</tr>
<tr>
<td><img width="32" src="https://www.datocms-assets.com/58478/1638283616-packer.svg"></td>
<td>Packer</td>
<td>coming-soon</td>
<td>📖 <a href="https://www.packer.io/">www.packer.io</a></td>
<td>⏩ coming-soon</td>
<td>✔️ <a href="./topics/architecture/">Architecture</a></td>
</tr>
<tr>
<td><img height="28" src="https://skillicons.dev/icons?i=graphql" /></td>
<td>Microservices</td>
<td><a href="./topics/microservices/">microservices</a></td>
<td>📖 <a href="https://aws.amazon.com/microservices/">aws/microservices</a></td>
<td>✔️ <a href="./topics/microservices/basic/">basic demo</a></td>
</tr>
<tr>
<td><img width="32" src="https://www.datocms-assets.com/58478/1638283616-packer.svg"></td>
<td>Packer</td>
<td>coming-soon</td>
<td>📖 <a href="https://www.packer.io/">www.packer.io</a></td>
<td>⏩ coming-soon</td>
</tr>
<tr>
Expand Down
4 changes: 4 additions & 0 deletions topics/microservices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
- Microservices architecture design: https://learn.microsoft.com/en-us/azure/architecture/microservices/
- aks-microservices: [aks-microservices](https://learn.microsoft.com/en-us/azure/architecture/reference-architectures/containers/aks-microservices/aks-microservices)
- https://dotnet.microsoft.com/en-us/learn/aspnet/microservices-architecture

## Hands-on
### Basics
- Checkout [basic](./basic/) content
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions topics/microservices/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Demo microservices

- Using GCP demo: https://github.com/GoogleCloudPlatform/microservices-demo
- Manifest: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/release/kubernetes-manifests.yaml

## 1. Provision K8s cluster

- Find the installation via [k8s](../../k8s/) content

## 2. Run hello microservices script

Prerequisite:

- A k8s cluster up and running (step 1)

Run:

```bash
./hello-microservices.sh
```

This will deploy the application then forward the service to port `8080` (or you could adjust to another port works with you machine)

## 3. Check the result

Visit localhost:8080, you should get the similar result like this:

![first-demo-microservices-result](../assets/first-demo-microservices-result.png)

## 4. Cleanup

Run:

```bash
./cleanup-hello-microservices.sh
```
5 changes: 5 additions & 0 deletions topics/microservices/basic/cleanup-hello-microservices.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

NAME_SPACE="demo-app"

kubectl delete namespace $NAME_SPACE
41 changes: 41 additions & 0 deletions topics/microservices/basic/hello-microservices.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

console_log() {
echo ">>> [Microservices] $1"
}

# Variables
NAME_SPACE="demo-app"

# Deploy
console_log "Deploying the services"
console_log "NAME_SPACE: $NAME_SPACE"

if kubectl get namespace "$NAME_SPACE" &>/dev/null; then
console_log "Namespace $NAME_SPACE already exists."
else
console_log "Namespace $NAME_SPACE does not exist. Creating..."
kubectl create namespace "$NAME_SPACE"
fi

kubectl apply -n $NAME_SPACE -f https://raw.githubusercontent.com/GoogleCloudPlatform/microservices-demo/main/release/kubernetes-manifests.yaml
kubectl get pods -n $NAME_SPACE

# Wait for services up
console_log "Waiting for all services are up. Sleeping 120s..."
# sleep 120

console_log "Checking all resouces in namespace '$NAME_SPACE'"
kubectl get all -n $NAME_SPACE

console_log "Checking pods"
kubectl get pods -n $NAME_SPACE

# Port forward
console_log "Forward the 'service/frontend' service"
## NOTE: You can change the '8080' port to whatever works on your machine
kubectl port-forward service/frontend -n $NAME_SPACE 8080:80

# Access the application
## Visit http://localhost:8080 to check your application

0 comments on commit 8b79ead

Please sign in to comment.