Skip to content

Commit

Permalink
ADM-733[docs] feat: creat deploy file guide how to deploy by k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoDai committed Feb 2, 2024
1 parent da8b7e9 commit 18db1e5
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
---
title: How to deploy heartbeat in multiple instances by k8s
description: How to deploy heartbeat in multiple instances by k8s
---

## Solutions

Following the next tutorial, you can use Heartbeat in the k8s environment more conveniently.

### Step 1: create a namespace

If you don't have heartbeat namespace, create one.

```shell
kubectl create namespace heartbeat
```

### Step 2: create pv and pvc

#### 2.1 Create pv

Create file `k8s-persistent-volume.yaml` and run `kubectl apply -f k8s-persistent-volume.yaml` to deploy pv.

- k8s-persistent-volume.yaml

You can use this command to create file `k8s-persistent-volume.yaml` with filled in content.

```shell
echo 'apiVersion: v1
kind: PersistentVolume
metadata:
name: pv
namespace: heartbeat
spec:
capacity:
storage: 200Mi
accessModes:
- ReadWriteMany
storageClassName: heartbeat
hostPath:
path: /data' > k8s-persistent-volume.yaml
```

Then you can use this command to deploy pv.

```shell
kubectl apply -f k8s-persistent-volume.yaml
```

You can use `kubectl get pv pv` to confirm whether the pv is created successfully.

```shell
kubectl get pv pv
```

#### 2.2 Create pvc

Create file `k8s-persistent-volume-claim.yaml` and run `kubectl apply -f k8s-persistent-volume-claim.yaml` to deploy pvc.

- k8s-persistent-volume-claim.yaml

You can use this command to create file `k8s-persistent-volume-claim.yaml` with filled in content.

```shell
echo 'apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc
namespace: heartbeat
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 200Mi
storageClassName: heartbeat' > k8s-persistent-volume-claim.yaml
```

Then you can use this command to deploy pvc.

```shell
kubectl apply -f k8s-persistent-volume-claim.yaml
```

You can use `kubectl get pvc -n heartbeat` to confirm whether the pvc is created successfully.

```shell
kubectl get pvc -n heartbeat
```

### Step 3: deploy backend

#### 3.1 Create backend service

Create file `k8s-backend-service.yaml` and run `kubectl apply -f k8s-backend-service.yaml` to create backend service.

- k8s-backend-service.yaml

You can use this command to create file `k8s-backend-service.yaml` with filled in content.

```shell
echo 'apiVersion: v1
kind: Service
metadata:
namespace: heartbeat
name: backend
labels:
app: backend
spec:
selector:
app: backend
ports:
- protocol: TCP
port: 4322
targetPort: 4322' > k8s-backend-service.yaml
```

Then you can use this command to deploy backend service.

```shell
kubectl apply -f k8s-backend-service.yaml
```

You can use `kubectl get services -n heartbeat` to confirm whether the backend service is created successfully.

```shell
kubectl get services -n heartbeat
```

#### 3.2 Deploy backend pods

Create `k8s-backend-deployment.yaml` and run `kubectl apply -f k8s-backend-deployment.yaml` to deploy backend deployment.

- k8s-backend-deployment.yaml

You can use this command to create file `k8s-backend-deployment.yaml` with filled in content.

```shell
echo 'apiVersion: apps/v1
kind: Deployment
metadata:
namespace: heartbeat
name: backend
labels:
app: backend
spec:
replicas: 3
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
initContainers:
- name: backend-init
image: busybox
securityContext:
runAsUser: 0
volumeMounts:
- name: volumes
mountPath: /app/output
command: ["sh", "-c", "chown -R 999:999 /app/output"]
containers:
- name: backend
image: ghcr.io/au-heartbeat/heartbeat_backend:latest
volumeMounts:
- name: volumes
mountPath: /app/output
volumes:
- name: volumes
persistentVolumeClaim:
claimName: pvc' > k8s-backend-deployment.yaml
```

Then you can use this command to deploy backend deployment.

```shell
kubectl apply -f k8s-backend-deployment.yaml
```

You can use `kubectl get pods -n heartbeat` to confirm whether the backend pods is created successfully.

```shell
kubectl get pods -n heartbeat
```

### Step 4: deploy frontend

#### 4.1 Create frontend service

Create `k8s-frontend-service.yaml` and run `kubectl apply -f k8s-frontend-service.yaml` to create frontend service.

- k8s-frontend-service.yaml

You can use this command to create file `k8s-frontend-service.yaml` with filled in content.

```shell
echo 'apiVersion: v1
kind: Service
metadata:
namespace: heartbeat
name: frontend
labels:
app: frontend
spec:
selector:
app: frontend
ports:
- protocol: TCP
port: 4321
targetPort: 80
type: LoadBalancer' > k8s-frontend-service.yaml
```

Then you can use this command to deploy frontend service.

```shell
kubectl apply -f k8s-frontend-service.yaml
```

You can use `kubectl get services -n heartbeat` to confirm whether the frontend service is created successfully.

```shell
kubectl get services -n heartbeat
```

#### 4.2 Deploy frontend pods

Create `k8s-frontend-deployment.yaml` and run `kubectl apply -f k8s-frontend-deployment.yaml` to deploy frontend deployment.

- k8s-frontend-deployment.yaml

You can use this command to create file `k8s-frontend-deployment.yaml` with filled in content.

```shell
echo 'apiVersion: apps/v1
kind: Deployment
metadata:
namespace: heartbeat
name: frontend
labels:
app: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: ghcr.io/au-heartbeat/heartbeat_frontend:latest' > k8s-frontend-deployment.yaml
```

Then you can use this command to deploy frontend service.

```shell
kubectl apply -f k8s-frontend-deployment.yaml
```

You can use `kubectl get pods -n heartbeat` to confirm whether the frontend pods is created successfully.

```shell
kubectl get pods -n heartbeat
```
7 changes: 7 additions & 0 deletions docs/src/i18n/en/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export default [
{ text: 'Way of Working', slug: 'onboarding/way-of-working', key: 'onboarding/way-of-working' },
{ text: 'Conventions', slug: 'onboarding/conventions', key: 'onboarding/conventions' },

{ text: 'DevOps', header: true, type: 'tech', key: 'devops' },
{
text: 'How to deploy heartbeat in multiple instances by k8s',
slug: 'devops/how-to-deploy-heartbeat-in-multiple-instances-by-k8s',
key: 'devops/how-to-deploy-heartbeat-in-multiple-instances-by-k8s',
},

{ text: 'Guides', header: true, type: 'tech', key: 'guides' },
{
text: 'Guideline and best practices',
Expand Down

0 comments on commit 18db1e5

Please sign in to comment.