优化
This commit is contained in:
112
docker/simple/k8s/README.md
Normal file
112
docker/simple/k8s/README.md
Normal file
@@ -0,0 +1,112 @@
|
||||
Its doc will tell you how to deploy `Tailchat` in kubeneters.
|
||||
|
||||
## One Command
|
||||
|
||||
```bash
|
||||
kubectl apply -f namespace.yml -f pv.yml -f mongo.yml -f minio.yml -f redis.yml -f tailchat.yml
|
||||
```
|
||||
|
||||
### Delete
|
||||
|
||||
if you wanna delete all resource, just delete namespace.
|
||||
|
||||
```bash
|
||||
kubectl delete -f namespace.yml
|
||||
```
|
||||
|
||||
## Setup one by one
|
||||
|
||||
### Create Namespace
|
||||
|
||||
```bash
|
||||
kubectl apply -f namespace.yml
|
||||
```
|
||||
|
||||
### Create Persistent Volume
|
||||
|
||||
```bash
|
||||
kubectl apply -f pv.yml
|
||||
```
|
||||
|
||||
### Create Mongodb
|
||||
|
||||
```bash
|
||||
kubectl apply -f mongo.yml
|
||||
```
|
||||
|
||||
### Create Minio
|
||||
|
||||
```bash
|
||||
kubectl apply -f minio.yml
|
||||
```
|
||||
|
||||
### Create Redis
|
||||
|
||||
```bash
|
||||
kubectl apply -f redis.yml
|
||||
```
|
||||
|
||||
### Create Tailchat
|
||||
|
||||
```bash
|
||||
kubectl apply -f tailchat.yml
|
||||
```
|
||||
|
||||
## Check tailchat-service work
|
||||
|
||||
#### get services ClusterIP
|
||||
```bash
|
||||
kubectl get svc -n tailchat
|
||||
```
|
||||
|
||||
#### create test container in kubernetes
|
||||
|
||||
```bash
|
||||
kubectl run -it --rm test-pod --image=busybox --restart=Never
|
||||
```
|
||||
|
||||
#### request health and checkout `nodeID`, send multi times.
|
||||
```
|
||||
wget -q -O - http://<tailchat-cluster-ip>:11000/health
|
||||
```
|
||||
|
||||
## Router and Load Balance
|
||||
|
||||
For example, we use traefik.
|
||||
|
||||
### Install Traefik provider
|
||||
|
||||
```bash
|
||||
helm repo add traefik https://helm.traefik.io/traefik
|
||||
helm install traefik traefik/traefik -n tailchat
|
||||
```
|
||||
|
||||
### Apply Ingress Config
|
||||
|
||||
```bash
|
||||
kubectl apply -f ingress.yml
|
||||
```
|
||||
|
||||
### Check Status
|
||||
|
||||
```bash
|
||||
kubectl get services -n tailchat
|
||||
```
|
||||
|
||||
If every is ok, its should be like this:
|
||||
|
||||

|
||||
|
||||
### Set DNS record
|
||||
|
||||
```bash
|
||||
sudo vim /etc/hosts
|
||||
```
|
||||
|
||||
append this record:
|
||||
|
||||
```
|
||||
127.0.0.1 tailchat.internal.com
|
||||
```
|
||||
|
||||
Now you can open browser and view `http://tailchat.internal.com` to open tailchat in k8s.
|
||||
BIN
docker/simple/k8s/images/traefik-svc.png
Normal file
BIN
docker/simple/k8s/images/traefik-svc.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
19
docker/simple/k8s/ingress.yml
Normal file
19
docker/simple/k8s/ingress.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: ingress
|
||||
namespace: tailchat
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/routing-type: edge
|
||||
spec:
|
||||
rules:
|
||||
- host: tailchat.internal.com
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: tailchat-service
|
||||
port:
|
||||
number: 11000
|
||||
55
docker/simple/k8s/minio.yml
Normal file
55
docker/simple/k8s/minio.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: minio
|
||||
namespace: tailchat
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: minio
|
||||
serviceName: minio
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: minio
|
||||
spec:
|
||||
containers:
|
||||
- name: minio
|
||||
image: minio/minio
|
||||
imagePullPolicy: IfNotPresent
|
||||
env:
|
||||
- name: MINIO_ROOT_USER
|
||||
value: tailchat
|
||||
- name: MINIO_ROOT_PASSWORD
|
||||
value: com.msgbyte.tailchat
|
||||
command:
|
||||
- minio
|
||||
- server
|
||||
- /data/storage
|
||||
- '--console-address'
|
||||
- ':9001'
|
||||
ports:
|
||||
- containerPort: 9000
|
||||
- containerPort: 9001
|
||||
volumeMounts:
|
||||
- name: minio-persistent-storage
|
||||
mountPath: /data/tailchat/storage
|
||||
volumes:
|
||||
- name: minio-persistent-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: minio-pvc
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: minio-service
|
||||
namespace: tailchat
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: minio
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 9000
|
||||
targetPort: 9000
|
||||
43
docker/simple/k8s/mongo.yml
Normal file
43
docker/simple/k8s/mongo.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: mongo
|
||||
namespace: tailchat
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: mongo
|
||||
serviceName: mongo
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: mongo
|
||||
spec:
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:4
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 27017
|
||||
volumeMounts:
|
||||
- name: mongo-persistent-storage
|
||||
mountPath: /data/tailchat/db
|
||||
volumes:
|
||||
- name: mongo-persistent-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: mongo-pvc
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: mongo-service
|
||||
namespace: tailchat
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: mongo
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 27017
|
||||
targetPort: 27017
|
||||
4
docker/simple/k8s/namespace.yml
Normal file
4
docker/simple/k8s/namespace.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: tailchat
|
||||
51
docker/simple/k8s/pv.yml
Normal file
51
docker/simple/k8s/pv.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: mongo-pv
|
||||
spec:
|
||||
storageClassName: tailchat-db
|
||||
capacity:
|
||||
storage: 5Gi
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath:
|
||||
path: /data/tailchat/db
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: mongo-pvc
|
||||
namespace: tailchat
|
||||
spec:
|
||||
storageClassName: tailchat-db
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: minio-pv
|
||||
spec:
|
||||
storageClassName: tailchat-storage
|
||||
capacity:
|
||||
storage: 5Gi
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath:
|
||||
path: /data/tailchat/storage
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: minio-pvc
|
||||
namespace: tailchat
|
||||
spec:
|
||||
storageClassName: tailchat-storage
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi
|
||||
36
docker/simple/k8s/redis.yml
Normal file
36
docker/simple/k8s/redis.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: redis
|
||||
namespace: tailchat
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: redis
|
||||
serviceName: redis
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: redis
|
||||
spec:
|
||||
containers:
|
||||
- name: redis
|
||||
image: redis:alpine
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: redis-service
|
||||
namespace: tailchat
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: redis
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 6379
|
||||
targetPort: 6379
|
||||
76
docker/simple/k8s/tailchat.yml
Normal file
76
docker/simple/k8s/tailchat.yml
Normal file
@@ -0,0 +1,76 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: tailchat
|
||||
namespace: tailchat
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: tailchat
|
||||
serviceName: tailchat
|
||||
replicas: 3
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: tailchat
|
||||
spec:
|
||||
containers:
|
||||
- name: tailchat
|
||||
image: moonrailgun/tailchat
|
||||
# imagePullPolicy: Always
|
||||
env:
|
||||
- name: SERVICEDIR
|
||||
value: services,plugins
|
||||
- name: TRANSPORTER
|
||||
value: redis://redis-service:6379
|
||||
- name: REDIS_URL
|
||||
value: redis://redis-service:6379
|
||||
- name: MONGO_URL
|
||||
value: mongodb://mongo-service/tailchat
|
||||
- name: SECRET
|
||||
value: any-secret-keywords
|
||||
- name: MINIO_URL
|
||||
value: minio-service:9000
|
||||
- name: MINIO_USER
|
||||
value: tailchat
|
||||
- name: MINIO_PASS
|
||||
value: com.msgbyte.tailchat
|
||||
ports:
|
||||
- containerPort: 11000
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 11000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 2
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 11000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 2
|
||||
failureThreshold: 3
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 51Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: tailchat-service
|
||||
namespace: tailchat
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: tailchat
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 11000
|
||||
targetPort: 11000
|
||||
Reference in New Issue
Block a user