日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

k8s~为服务添加sidecar边斗

發(fā)布時間:2023/12/15 综合教程 32 生活家
生活随笔 收集整理的這篇文章主要介紹了 k8s~为服务添加sidecar边斗 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

sidecar這個詞一般指帶有跨斗的摩托車,在二戰(zhàn)時候小日本開著很多這種摩托車,它在原有基礎上添加了一個跨斗,之后就可以多載一個人,而對于原來的兩輪摩托車沒有什么影響,把跨斗拆了也是可以的,對原來的事物沒有本質上的破壞,只是擴展了新的功能,這與軟件開發(fā)里的OCP原則很像,在服務網(wǎng)格的istio里也有這個概念,它把這種組件叫“sidecar”,在istio里sidecar也只是一個概念,具體是由envoy來實現(xiàn)的。

具體fluentd功能的sidecar

我們的容器部署到k8s里,通過k8s來管理我們的容器,實現(xiàn)對容器的生命周期管理,服務發(fā)現(xiàn)管理,多副本管理等等;而我們把這些容器可以理解為一個個的微服務,而這些服務的日志一般先記錄在本地,然后推到elasticsearch里,而日志收集工具我們可以選擇fluentFilebeatLogstash等等。

添加fluentd的sidecar

添加fluentd.config配置

<source>
type tail
format json
path /var/log/*.log
pos_file /var/log/log.pos
tag saas #這個是es里索引的名稱,可以在kibana里建立索引
</source>

<match **>
@id elasticsearch
@type elasticsearch
@log_level debug
index_name fluentd
type_name _doc
host elasticsearch.elk
port 9200
include_tag_key true
tag_key @log_name
logstash_format true
logstash_prefix saas
flush_interval 10s
</match>

服務的部署文件添加sidecar

kind: Service
apiVersion: v1
metadata:
  name: hello-world
  namespace: saas
spec:
  selector:
    app: hello-world
  type: ClusterIP
  ports:
    - protocol: TCP
      targetPort: 9001
      port: 80
---
# 構建反射代理
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: hello-world-ingress
  namespace: saas
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  tls:
    - hosts:
        - www.abc.com
      secretName: saas-tls
  rules:
    - host: www.abc.com
      http:
        paths:
          - backend:
              serviceName: hello-world
              servicePort: 9001
          - path: /dotnet
            backend:
              serviceName: dotnet-hello
              servicePort: 80
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: hello-world-deployment
  namespace: saas
  labels:
    app: hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello-world
          image: 172.17.0.22:8888/saas/hello-world:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 9001
          env:
            - name: spring.profiles.active
              value: prod
          volumeMounts:
            - name: varlog
              mountPath: /var/log
        - name: fluent-sidecar
          image: registry.cn-beijing.aliyuncs.com/k8s-mqm/fluentd-elasticsearch:v2.1.0
          env:
            - name: FLUENTD_ARGS
              value: -c /etc/fluentd-config/fluentd.conf
          volumeMounts:
            - name: varlog
              mountPath: /var/log
            - name: config-volume
              mountPath: /etc/fluentd-config
      volumes:
        - name: varlog
          emptyDir: {}
        - name: config-volume
          configMap:
            name: fluentd-config

當你的hello-world部署到k8s之后,在有日志記錄時它會寫到/var/logs目錄,而fluentd這個sidecar因為是與容器花用的磁盤,所以它也可以讀到日志的內容,然后把日志發(fā)到elasticsearch里。

總結

以上是生活随笔為你收集整理的k8s~为服务添加sidecar边斗的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。