K8S部署skywalking

一、安装K8S集群

kubeadm部署k8s v1.16.2+docker 18.06.3集群

二、部署skywalking

2.1.创建命名空间

kubectl create ns skywalking

2.2.给节点打标签

kubectl label node 节点名 nodetype=wedesign

2.3.skywalking-oap.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: oap
  namespace: skywalking
spec:
  replicas: 1
  selector:
    matchLabels:
      app: oap
      release: skywalking
  template:
    metadata:
      labels:
        app: oap
        release: skywalking
    spec:
      nodeSelector:
       nodetype: wedesign
      containers:
        - name: oap
          image: apache/skywalking-oap-server:6.6.0-es6
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 11800
              name: grpc
            - containerPort: 12800
              name: rest
---
apiVersion: v1
kind: Service
metadata:
  name: oap
  namespace: skywalking
  labels:
    service: oap
spec:
  ports:
    - port: 12800
      name: rest
    - port: 11800
      name: grpc
  selector:
    app: oap

kubectl apply -f skywalking-oap.yml

2.4.skywalking-ui.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui-deployment
  namespace: skywalking
  labels:
    app: ui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ui
  template:
    metadata:
      labels:
        app: ui
    spec:
      nodeSelector:
       nodetype: wedesign
      containers:
        - name: ui
          image: apache/skywalking-ui:6.6.0
          ports:
            - containerPort: 8080
              name: page
          env:
            - name: SW_OAP_ADDRESS
              value: oap:12800
---
apiVersion: v1
kind: Service
metadata:
  name: ui
  namespace: skywalking
  labels:
    service: ui
spec:
  ports:
    - port: 8080
      name: page
      nodePort: 31008
  type: NodePort
  selector:
    app: ui

kubectl apply -f skywalking-ui.yml

2.5.访问

http://NodeIP:31008
在这里插入图片描述

三、sidecar 模式挂载 agent

参考文章:https://skywalking.apache.org/zh/blog/2019-08-30-how-to-use-Skywalking-Agent.html
在这里插入图片描述

四、微服务对接skywalking

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: web
  replicas: 1
  template:
    metadata:
      labels:
        app: web
    spec:
      initContainers:
        - image: spring2go/skywalking-agent-sidecar:6.6.0
          name: sw-agent-sidecar
          imagePullPolicy: IfNotPresent
          command: ["sh"]
          args:
            [
              "-c",
              "mkdir -p /skywalking/agent && cp -r /usr/skywalking/agent/* /skywalking/agent",
            ]
          volumeMounts:
            - mountPath: /skywalking/agent
              name: sw-agent
      containers:
        - name: web
          image: spring2go/spring-petclinic-web-app:1.0.0.RELEASE
          env:
            - name: JAVA_OPTS
              value: -javaagent:/usr/skywalking/agent/skywalking-agent.jar
            - name: SW_AGENT_NAME
              value: petclinic-web
            - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
              value: oap.skywalking:11800 # FQDN: servicename.namespacename.svc.cluster.local
            - name: SERVER_PORT
              value: "8080"
            - name: VISITS_SERVICE_ENDPOINT
              value: http://visits:8080
            - name: CUSTOMERS_SERVICE_ENDPOINT
              value: http://customers:8080
          volumeMounts:
            - mountPath: /usr/skywalking/agent
              name: sw-agent
      volumes:
        - name: sw-agent
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    svc: web
spec:
  selector:
    app: web
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  type: ClusterIP

注意:在java启动jar包时需要在java后面添加${JAVA_OPTS}变量,如java ${JAVA_OPTS} -jar /opt/app.jar;如果不是用root用户启动java程序【例如devops】,还需要修改/usr/skywalking目录的所有者为devops

chown -R devops.devops /usr/skywalking
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页