tongyi007 发表于 2019-2-20 10:40:48

Docker(三十三)k8s 监控以及容器之间调用关系

  主要是观察各个pod 之间的调用关系,选用weave-scope
  安装
curl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yamlcurl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yamlcurl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yamlcurl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yamlcurl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yamlcurl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yaml
  获取当前k8s 当前版本的scope 文件,我用的是1.8.13
  文件内容如下
apiVersion: v1
kind: List
items:
- apiVersion: v1
    kind: Namespace
    metadata:
      name: weave
      annotations:
      cloud.weave.works/version: unknown
- apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: weave-scope
      annotations:
      cloud.weave.works/launcher-info: |-
          {
            "original-request": {
            "url": "/k8s/scope.yaml?k8s-version=1.8.13",
            "date": "Mon Nov 19 2018 07:21:43 GMT+0000 (UTC)"
            },
            "email-address": "support@weave.works"
          }
      labels:
      name: weave-scope
      namespace: weave
- apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRole
    metadata:
      name: weave-scope
      annotations:
      cloud.weave.works/launcher-info: |-
          {
            "original-request": {
            "url": "/k8s/scope.yaml?k8s-version=1.8.13",
            "date": "Mon Nov 19 2018 07:21:43 GMT+0000 (UTC)"
            },
            "email-address": "support@weave.works"
          }
      labels:
      name: weave-scope
    rules:
      - apiGroups:
          - ''
      resources:
          - pods
      verbs:
          - get
          - list
          - watch
          - delete
      - apiGroups:
          - ''
      resources:
          - pods/log
          - services
          - nodes
          - namespaces
          - persistentvolumes
          - persistentvolumeclaims
      verbs:
          - get
          - list
          - watch
      - apiGroups:
          - apps
      resources:
          - statefulsets
      verbs:
          - get
          - list
          - watch
      - apiGroups:
          - batch
      resources:
          - cronjobs
          - jobs
      verbs:
          - get
          - list
          - watch
      - apiGroups:
          - extensions
      resources:
          - deployments
          - daemonsets
      verbs:
          - get
          - list
          - watch
      - apiGroups:
          - extensions
      resources:
          - deployments/scale
      verbs:
          - get
          - update
      - apiGroups:
          - storage.k8s.io
      resources:
          - storageclasses
      verbs:
          - get
          - list
          - watch
- apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: weave-scope
      annotations:
      cloud.weave.works/launcher-info: |-
          {
            "original-request": {
            "url": "/k8s/scope.yaml?k8s-version=1.8.13",
            "date": "Mon Nov 19 2018 07:21:43 GMT+0000 (UTC)"
            },
            "email-address": "support@weave.works"
          }
      labels:
      name: weave-scope
    roleRef:
      kind: ClusterRole
      name: weave-scope
      apiGroup: rbac.authorization.k8s.io
    subjects:
      - kind: ServiceAccount
      name: weave-scope
      namespace: weave
- apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: weave-scope-app
      annotations:
      cloud.weave.works/launcher-info: |-
          {
            "original-request": {
            "url": "/k8s/scope.yaml?k8s-version=1.8.13",
            "date": "Mon Nov 19 2018 07:21:43 GMT+0000 (UTC)"
            },
            "email-address": "support@weave.works"
          }
      labels:
      name: weave-scope-app
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: app
      namespace: weave
    spec:
      replicas: 1
      revisionHistoryLimit: 2
      template:
      metadata:
          labels:
            name: weave-scope-app
            app: weave-scope
            weave-cloud-component: scope
            weave-scope-component: app
      spec:
          containers:
            - name: app
            args:
                - '--mode=app'
            command:
                - /home/weave/scope
            env: []
            image: 'docker.io/weaveworks/scope:1.9.1'
            imagePullPolicy: IfNotPresent
            ports:
                - containerPort: 4040
                  protocol: TCP
- apiVersion: v1
    kind: Service
    metadata:
      name: weave-scope-app
      annotations:
      cloud.weave.works/launcher-info: |-
          {
            "original-request": {
            "url": "/k8s/scope.yaml?k8s-version=1.8.13",
            "date": "Mon Nov 19 2018 07:21:43 GMT+0000 (UTC)"
            },
            "email-address": "support@weave.works"
          }
      labels:
      name: weave-scope-app
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: app
      namespace: weave
    spec:
      ports:
      - name: app
          port: 80
          protocol: TCP
          targetPort: 4040
      selector:
      name: weave-scope-app
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: app
- apiVersion: extensions/v1beta1
    kind: DaemonSet
    metadata:
      name: weave-scope-agent
      annotations:
      cloud.weave.works/launcher-info: |-
          {
            "original-request": {
            "url": "/k8s/scope.yaml?k8s-version=1.8.13",
            "date": "Mon Nov 19 2018 07:21:43 GMT+0000 (UTC)"
            },
            "email-address": "support@weave.works"
          }
      labels:
      name: weave-scope-agent
      app: weave-scope
      weave-cloud-component: scope
      weave-scope-component: agent
      namespace: weave
    spec:
      minReadySeconds: 5
      template:
      metadata:
          labels:
            name: weave-scope-agent
            app: weave-scope
            weave-cloud-component: scope
            weave-scope-component: agent
      spec:
          containers:
            - name: scope-agent
            args:
                - '--mode=probe'
                - '--probe-only'
                - '--probe.kubernetes=true'
                - '--probe.docker.bridge=docker0'
                - '--probe.docker=true'
                - 'weave-scope-app.weave.svc.cluster.local:80'
            command:
                - /home/weave/scope
            env:
                - name: KUBERNETES_NODENAME
                  valueFrom:
                  fieldRef:
                      apiVersion: v1
                      fieldPath: spec.nodeName
            image: 'docker.io/weaveworks/scope:1.9.1'
            imagePullPolicy: IfNotPresent
            securityContext:
                privileged: true
            volumeMounts:
                - name: scope-plugins
                  mountPath: /var/run/scope/plugins
                - name: sys-kernel-debug
                  mountPath: /sys/kernel/debug
                - name: docker-socket
                  mountPath: /var/run/docker.sock
          dnsPolicy: ClusterFirstWithHostNet
          hostNetwork: true
          hostPID: true
          serviceAccountName: weave-scope
          tolerations:
            - effect: NoSchedule
            operator: Exists
          volumes:
            - name: scope-plugins
            hostPath:
                path: /var/run/scope/plugins
            - name: sys-kernel-debug
            hostPath:
                path: /sys/kernel/debug
            - name: docker-socket
            hostPath:
                path: /var/run/docker.sock
      updateStrategy:
      type: RollingUpdate  这里已经给分配好了namespace,所以直接部署就好
kubectl apply -f scope.yamlkubectl apply -f scope.yaml  kubectl apply -f scope.yaml

  然后分配好ip 地址,自己能访问到的,如果是公有云,有需要制定k8s 的直接,然后暴露公网地址



页: [1]
查看完整版本: Docker(三十三)k8s 监控以及容器之间调用关系