Google 云上的 Kubernetes 集群,带有简单的 Flask 应用程序和 ELK 堆栈

问题描述 投票:0回答:1

使用 Flask,我制作了一个应用程序,将 get 请求的键和值打印到控制台。我的目标是创建一个包含 1 个主节点和 2 个工作节点的集群,并安装 Flask 应用程序和 ELK 堆栈用于登录。我已经在Google云上创建了集群(4个CPU 8GB内存)。我为 Flask 应用程序创建了一个 docker 映像并将其上传到集线器。我想使用 HELM 安装 ELK 堆栈。但豆荚不工作。它保持待处理状态。我正在使用 HELM 的默认图表。我没有做任何编辑。我应该怎么办?感谢您的帮助。

编辑:这是我用于elasticsearch的deployment.yaml文件(我无法用helm处理它,请继续尝试使用yaml文件)

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: elasticsearch
  namespace: elk-stack
spec:
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
        - name: elasticsearch
          image: elasticsearch:7.6.2
          resources:
            requests:
              memory: 1Gi
              cpu: 1
            limits:
              memory: 2Gi
              cpu: 2

这是

kubectl get pods -n elk-stack -o wide command
的输出:

NAME                            READY   STATUS             RESTARTS      AGE   IP           NODE                                            NOMINATED NODE   READINESS GATES
elasticsearch-c49749bbc-db9pt   0/1     CrashLoopBackOff   3 (35s ago)   95s   10.84.0.11   gke-devops-cluster-default-pool-8155544c-978l   <none>           <none>

这是

kubectl top node
的输出:

NAME                                            CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
gke-devops-cluster-default-pool-8155544c-3mkr   73m          7%     1318Mi          46%       
gke-devops-cluster-default-pool-8155544c-978l   94m          10%    1194Mi          42%

这是

kubectl describe pods -n elk-stack
的输出:

Name:             elasticsearch-c49749bbc-db9pt
Namespace:        elk-stack
Priority:         0
Service Account:  default
Node:             gke-devops-cluster-default-pool-8155544c-978l/10.156.0.24
Start Time:       Mon, 31 Jul 2023 21:15:00 +0300
Labels:           app=elasticsearch
                  pod-template-hash=c49749bbc
Annotations:      <none>
Status:           Running
IP:               10.84.0.11
IPs:
  IP:           10.84.0.11
Controlled By:  ReplicaSet/elasticsearch-c49749bbc
Containers:
  elasticsearch:
    Container ID:   containerd://c2532904c4a2551f1ff2c8df924fb7704186a9924cfb6b491e7d6996407a3aa5
    Image:          elasticsearch:7.6.2
    Image ID:       docker.io/library/elasticsearch@sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Mon, 31 Jul 2023 21:18:27 +0300
      Finished:     Mon, 31 Jul 2023 21:18:31 +0300
    Ready:          False
    Restart Count:  5
    Limits:
      cpu:     500m
      memory:  700Mi
    Requests:
      cpu:        300m
      memory:     500Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-7kjrr (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-7kjrr:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                     From               Message
  ----     ------     ----                    ----               -------
  Normal   Scheduled  4m41s                   default-scheduler  Successfully assigned elk-stack/elasticsearch-c49749bbc-db9pt to gke-devops-cluster-default-pool-8155544c-978l
  Normal   Pulled     2m48s (x5 over 4m41s)   kubelet            Container image "elasticsearch:7.6.2" already present on machine
  Normal   Created    2m48s (x5 over 4m41s)   kubelet            Created container elasticsearch
  Normal   Started    2m48s (x5 over 4m41s)   kubelet            Started container elasticsearch
  Warning  BackOff    2m16s (x10 over 4m30s)  kubelet            Back-off restarting failed container elasticsearch in pod elasticsearch-c49749bbc-db9pt_elk-stack(90993e32-bcd8-4e96-b27b-d5b6d532a470)

我遵循了本教程:https://ardabatuhandemir.medium.com/helm-ile-kubernetes-ortam%C4%B1nda-elk-stack-kurulumu-f5ab8f934f99。我还查找了包含 ELK 部署到 k8s 的每个来源。

kubernetes google-cloud-platform google-kubernetes-engine kubernetes-helm elastic-stack
1个回答
0
投票

出于测试目的,您可以使用它,并让我知道:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: elasticsearch
  namespace: elk-stack
spec:
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
        - name: elasticsearch
          image: elasticsearch:7.17.5
          resources:
            requests:
              memory: 1Gi
              cpu: 1
            limits:
              memory: 2Gi
              cpu: 2
          env:
            - name: discovery.type
              value: "single-node" # Set the discovery.type to single-node

不要忘记,如果您决定通过 yaml 文件手动配置 ELK,您仍然需要安装 Logstash、kibana、处理卷和配置映射

© www.soinside.com 2019 - 2024. All rights reserved.