最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Kubernetes集群在某些处理后关闭

运维笔记admin18浏览0评论

Kubernetes集群在某些处理后关闭

Kubernetes集群在某些处理后关闭

我在运行NodeJS服务器的GCP上有一个集群。该服务器在本地运行良好,但是当我向一条路线发送帖子时停止运行,没有任何消息。这篇文章应该使用FCM向我的一些用户发送推送消息。我的数据库是Cloud Firestore。

Pod日志:

Not sending to xxxxxxxxxxxxxxx
Not sending to xxxxxxxxxxxxxyx

[email protected] prestart /opt/app
tsc


[email protected] start /opt/app
node src/index.js

Dockerfile:

FROM node:11.15-alpine

# install deps
ADD package.json /tmp/package.json
RUN apk update && apk add yarn python g++ make && rm -rf /var/cache/apk/*
RUN cd /tmp && npm install

# Copy deps
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app

# Setup workdir
WORKDIR /opt/app
COPY . /opt/app

# run
EXPOSE 3000
CMD ["npm", "start"] 

Kubernetes.yaml.tpl

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
  labels:
    app: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
        - name: app
          env:
          - name: var1
            value: value1
          - name: var2
            value: value2
          - name: var3
            value: value3
          - name: var4
            value: value4
          - name: var5
            value: value5
          - name: var6
            value: value6
          image: gcr.io/${PROJECT_ID}/app:COMMIT_SHA
          ports:
            - containerPort: 3000
          livenessProbe:
            httpGet:
              path: /alive
              port: 3000
            initialDelaySeconds: 30
          readinessProbe:
            httpGet:
              path: /alive
              port: 3000
            initialDelaySeconds: 30
            timeoutSeconds: 1

---
apiVersion: networking.gke.io/v1beta1
kind: ManagedCertificate
metadata:
  name: app
spec:
  domains:
    - myDomain.br
---
apiVersion: v1
kind: Service
metadata:
  name: app
spec:
  type: NodePort
  selector:
    app: app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app
  annotations:
    kubernetes.io/ingress.global-static-ip-name: "00.000.000.000"
    networking.gke.io/managed-certificates: app
spec:
  backend:
    serviceName: app
    servicePort: 80

正在调用的我的函数:

var query = tokens;
const getTokens = (
    doc: FirebaseFirestore.QueryDocumentSnapshot
) => {
    // Get user token and send push    
}

const canSend = (user: User): boolean => {
 // Apply business logic to check if the user will receive a push
}


let allUsers: FirebaseFirestore.QuerySnapshot = userdata;
let allGroups: FirebaseFirestore.QuerySnapshot = groups;
await this.asyncForEach(
   query.docs,
   async (doc: FirebaseFirestore.QueryDocumentSnapshot) => {
       let userDoc: User;
       allUsers.docs.filter(
           (userDoc) => userDoc.data()['userId'] === doc.data()['id']
       ).forEach((user: any) => {
           userDoc = new User(user);
       });
       if (userDoc) {
           if (canSend(userDoc)) {
               console.log(`Sending to: ${userDoc.id}`);
               await getTokens(doc);
           } else {
               console.log(`Not sending to: ${doc.data()['id']} `);
           }
        } else {
            console.log(`${doc.data()['id']} Has no document`);
        }
    }
);
console.log('Finished');

EDIT1

我刚刚注意到,当我的服务器发送大量请求或大量小的请求时,会发生这种情况>

编辑2

kubectl get events返回No resources found.

我在运行NodeJS服务器的GCP上有一个集群。该服务器在本地运行良好,但是当我向一条路线发送帖子时停止运行,没有任何消息。这篇文章应该向我的一些用户发送推送消息...

回答如下:

由OP确认,问题在于livenessProbe由于超时而失败,这导致吊舱终止。

发布评论

评论列表(0)

  1. 暂无评论