1. 程式人生 > >Docker(三十三)k8s 監控以及容器之間呼叫關係

Docker(三十三)k8s 監控以及容器之間呼叫關係

主要是觀察各個pod 之間的呼叫關係,選用weave-scope

安裝

curl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yaml
curl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yaml
curl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yaml
curl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yaml
curl https://cloud.weave.works/k8s/scope.yaml\?k8s-version\=1.8.13 -sL -o scope.yaml

curl 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": "
[email protected]
"           }       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": "[email protected]"           }       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": "[email protected]"           }       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": "[email protected]"           }       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": "[email protected]"           }       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": "[email protected]"           }       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.yaml
kubectl apply -f scope.yaml

kubectl apply -f scope.yaml


然後分配好ip 地址,自己能訪問到的,如果是公有云,有需要制定k8s 的直接,然後暴露公網地址