Skip to content

Instantly share code, notes, and snippets.

View harryge00's full-sized avatar

Haoyuan Ge harryge00

  • Ant Financial
  • Hangzhou
View GitHub Profile
@harryge00
harryge00 / kubernete_sum_cpu.sh
Created May 22, 2018 11:30
Calculate the total CPU limit of the first containers in a namespace of Kubernetes
kubectl get pods -n chenkunning-84 -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].resources.limits.cpu} {"\n"}{end}' |awk '{sum+=$2 ; print $0} END{print "sum=",sum}'
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@harryge00
harryge00 / Dockerfile.md
Last active June 1, 2018 01:57
Dockerfile entrypoint best practice

发现用户喜欢用while ... sleep...来写Dockerfile的 ENTRYPOINT

tail -f /dev/null 的开销小,还是

while true do sleep 3 done ?

前者更小,因为tail -f 会一直等待 I/O 完成,进程一直处于Waiting状态。

DEBU[0001] Using graph driver overlay2
DEBU[0001] Failed to load layer sha256:aa11f8b7cbe67d2079243d0123331063cc7a0dcf35e37ffa1f8e30bc7397585b: failed to get diff id for sha256:aa11f8b7cbe67d2079243d0123331063cc7a0dcf35e37ffa1f8e30bc7397585b: invalid checksum digest format
rm -rf /var/lib/docker/image/overlay2/layerdb/sha256/aa11f8b7cbe67d2079243d0123331063cc7a0dcf35e37ffa1f8e30bc7397585b
@harryge00
harryge00 / heapster-metric-influxdb
Created July 18, 2018 12:27
heapster指标介绍
cpu利用率: cpu/usage_rate
容器的cpu上限: cpu/limit
磁盘读速率:disk/io_read_bytes_rate
磁盘总的读比特:disk/io_write_bytes
磁盘写速率:disk/io_write_bytes_rate
缓存的内存使用量:memory/cache
容器的内存上限:memory/limit
rss内存:memory/rss
总的内存使用量:memory/usage
@harryge00
harryge00 / gist:7e07f5bb0e321512198018d2e6be6a96
Created August 2, 2018 04:10
golang 中flag.InitFlags()
需要保證vendor裏沒有重復的package
@harryge00
harryge00 / istio-demo.md
Last active August 13, 2018 11:46
bookinfo istio demo deployments cannot create pods
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  creationTimestamp: 2018-08-13T11:34:52Z
  name: psp:rootprivileged
  namespace: default
  resourceVersion: "263399"
  selfLink: /apis/rbac.authorization.k8s.io/v1/namespaces/default/roles/psp%3Arootprivileged
 uid: e512c27b-9eec-11e8-9bfa-0cc47ab1f848
@harryge00
harryge00 / InfluxDB.md
Created August 14, 2018 06:31
influxdb heapster kubernetes metrics query SQL

节点监控指标汇总

  • 这里以 10.35.48.177为例,可以访问172.25.3.194上面的influxdb进行测试
  • InfluxDB 包含mean、group by 等语法,可以视需要使用
  • 本文中仅为示例用法
  • 有些指标是固定的,比如总的的文件系统空间、节点总内存及可分配总内存、总cpu核数、GPU总显存,所以一般搜最新的就好

容器总的cpu利用率(单位%)

SELECT * FROM k8s."default"."cpu/node_utilization" WHERE (nodename =~ /^10.35.48.177$/ AND type = 'node') AND time >= now() - 1h;

-A KUBE-SEP-GS323OQVD4QXLLO4 -s 10.252.98.29/32 -m comment --comment "default/nginx-daemonset:web" -j KUBE-MARK-MASQ
-A KUBE-SEP-GS323OQVD4QXLLO4 -p tcp -m comment --comment "default/nginx-daemonset:web" -m tcp -j DNAT --to-destination 10.252.98.29:80
-A KUBE-SEP-RBNT5SR6IHU6F3JX -s 10.252.12.5/32 -m comment --comment "default/nginx-daemonset:web" -j KUBE-MARK-MASQ
-A KUBE-SEP-RBNT5SR6IHU6F3JX -p tcp -m comment --comment "default/nginx-daemonset:web" -m tcp -j DNAT --to-destination 10.252.12.5:80
-A KUBE-SEP-RZOSV3LCXBQS2YSF -s 10.252.63.2/32 -m comment --comment "default/nginx-daemonset:web" -j KUBE-MARK-MASQ
-A KUBE-SEP-RZOSV3LCXBQS2YSF -p tcp -m comment --comment "default/nginx-daemonset:web" -m tcp -j DNAT --to-destination 10.252.63.2:80
-A KUBE-SEP-ZHKBSEG7AL2NL7WQ -s 10.252.65.2/32 -m comment --comment "default/nginx-daemonset:web" -j KUBE-MARK-MASQ
-A KUBE-SEP-ZHKBSEG7AL2NL7WQ -p tcp -m comment --comment "default/nginx-daemonset:web" -m tcp -j DNAT --to-destination 10.252.65.2:80
-A KUBE-SERVICES ! -s
@harryge00
harryge00 / reuse.code
Created October 11, 2018 13:45
Protobuf in Kubernetes
unexpected ListAndWatch error: storage/cacher.go:/pods: Failed to list *core.Pod: unexpected EOF