K8S安装cadvisor
apiVersion: apps/v1nkind: DaemonSetnmetadata:n name: cadvisorn namespace: ns-monitornspec:n selector:n matchLabels
apiVersion: apps/v1nkind: DaemonSetnmetadata:n name: cadvisorn namespace: ns-monitornspec:n selector:n matchLabels:n app: cAdvisorn template:n metadata:n labels:n app: cAdvisorn spec:n tolerations: #污点容忍,忽略master的NoSchedulen - effect: NoSchedulen key: node-role.kubernetes.io/mastern hostNetwork: false #n restartPolicy: Always # 重启策略n containers:n - name: cadvisorn image: registry.cn-hangzhou.aliyuncs.com/sysu-faas/cadvisor:v0.45.0n imagePullPolicy: IfNotPresent # 镜像策略n ports:n - containerPort: 8080n hostPort: 8888 n volumeMounts:n - name: rootn mountPath: /rootfsn - name: runn mountPath: /var/runn - name: sysn mountPath: /sysn - name: dockern mountPath: /var/lib/containerdn volumes:n - name: rootn hostPath: n path: /n - name: runn hostPath:n path: /var/run n - name: sysn hostPath:n path: /sysn - name: dockern hostPath:n path: /var/lib/containerdn
之前总是报错cadvisor.go:179] listen tcp :8080: bind: address already in use
原因是本地已有localnode dns cache绑定了8080端口,因为DaemonSet默认使用的是hostNetwork: true
,即它们的网络命名空间与Node的主机网络命名空间共享,所以出现了错误。
需要将容器内的8080端口映射到node上的8888端口,并将hostNetwork设置为false
总之,容器端口由容器的ports字段指定,并由Kubernetes自动分配随机端口,并将其映射到Node上的随机端口,需要注意的是,容器端口和Pod级别的端口之间是一一对应的关系。这意味着你可以在Pod模板的spec
字段中指定Pod级别的端口,Kubernetes会自动将这些端口映射到容器的端口。
附带一张占了8080端口的NodeLocal DNSCache工作原理