可視化 Kubernetes 歷史記錄
簡介
Sloop 可以監控 Kubernetes event ,記錄事件和資源狀態變化的歷史,並提供可視化來幫助調試過去的事件。
主要特點:
-
允許查找和檢查不再存在的資源(例如:發現之前部署中的 pod )。
-
提供時間線顯示,顯示 deployment 、ReplicaSet 和 StatefulSet 更新中相關資源的退出。
-
幫助調試瞬態和間歇性錯誤。
-
可以查看 Kubernetes 應用程序中隨時間的變化。
-
是一個獨立的服務,不依賴於分佈式存儲。
架構
安裝及使用
docker 安裝
我們可以使用官方提供的鏡像安裝,sloop
數據文件保存在容器的 / data 目錄下
docker run -it -p 8080:8080 -v ~/.kube/config:/kube/config -v /data:/data -e KUBECONFIG=/kube/config sloopimage/sloop
通過訪問 https://localhost:8080 即可進入 web ui 。
在側邊欄我們可以選擇要查看的時間範圍,名稱空間,資源對象,以及關鍵詞過濾等。
在詳情頁面我們可以看到我們 event 的詳情
我們還可以點擊頁面裏的 details 查看資源對象的詳情
還可以點擊頁面上方的debug menu
進入 debug 頁面查看 metrics
我們還可以配置一下我們打開 ui 後的默認頁面,sloop 有如下選項
[root@dev-tools sloop]# docker run --rm -it -p 8080:8080 -v ~/.kube/config:/kube/config -e KUBECONFIG=/kube/config sloop sloop -h
Usage of configFileOnly:
-alsologtostderr
log to standard error as well as files
-apiserver-host string
Kubernetes API server endpoint
-badger-detail-log-enabled
Turns on detailed logging of BadgerDB
-badger-discard-ratio float
Badger value log GC uses this value to decide if it wants to compact a vlog file. The lower the value of discardRatio the higher the number of !badger!move keys. And thus more the number of !badger!move keys, the size on disk keeps on increasing over time.
-badger-enable-event-logging
Turns on badger event logging
-badger-keep-l0-in-memory
Keeps all level 0 tables in memory for faster writes and compactions
-badger-level-one-size int
The maximum total size for Level 1. 0 = use badger default
-badger-level-size-multiplier int
The ratio between the maximum sizes of contiguous levels in the LSM. 0 = use badger default
-badger-max-table-size int
Max LSM table size in bytes. 0 = use badger default
-badger-number-of-compactors int
Number of compactors for badger
-badger-number-of-level-zero-tables int
Number of level zero tables for badger
-badger-number-of-zero-tables-stall int
Number of Level 0 tables that once reached causes the DB to stall until compaction succeeds
-badger-sync-writes
Sync Writes ensures writes are synced to disk if set to true
-badger-use-lsm-only-options
Sets a higher valueThreshold so values would be collocated with LSM tree reducing vlog disk usage
-badger-vlog-file-size int
Max size in bytes per value log file. 0 = use badger default
-badger-vlog-fileIO-mapping
Indicates which file loading mode should be used for the value log data, in memory constrained environments the value is recommended to be true
-badger-vlog-gc-freq duration
Frequency of running badger's ValueLogGC
-badger-vlog-max-entries uint
Max number of entries per value log files. 0 = use badger default
-badger-vlog-truncate
Truncate value log if badger db offset is different from badger db size
-bind-address string
Web server bind ip address.
-cleanup-frequency duration
Frequency between subsequent runs for the database cleanup
-config string
Path to a yaml or json config file
-context string
Use a specific kubernetes context
-crd-refresh-interval duration
Frequency between CRD Informer refresh
-default-kind string
Default UX filter kind
-default-lookback string
Default UX filter lookback
-default-namespace string
Default UX filter namespace
-deletion-batch-size int
Size of batch for deletion
-disable-kube-watch
Turn off kubernetes watch
-disable-store-manager
Turn off store manager which is to clean up database
-display-context string
Use this to override the display context. When running in k8s the context is empty string. This lets you override that (mainly useful if you are running many copies of sloop on different clusters)
-enable-delete-keys
Use delete prefixes instead of dropPrefix for GC
-gc-threshold float
Threshold for GC to start garbage collecting
-keep-minor-node-updates
Keep all node updates even if change is only condition timestamps
-kube-watch-resync-interval duration
OPTIONAL: Kubernetes watch resync interval
-log_backtrace_at string
when logging hits line file:N, emit a stack trace
-logtostderr
log to standard error instead of files
-max-disk-mb int
Max disk storage in MB
-max-look-back duration
Max history data to keep
-playback-file string
Read watch data from a playback file
-port int
Web server port
-record-file string
Record watch data to a playback file
-restore-database-file string
Restore database from backup file into current context.
-stderrthreshold int
logs at or above this threshold go to stderr
-store-root string
Path to store history data
-use-mock-badger
Use a fake in-memory mock of badger
-v int
log level for V logs
-vmodule string
comma-separated list of pattern=N settings for file-filtered logging
-watch-crds
Watch for activity for CRDs
-web-files-path string
Path to web files
Failed to pre-parse flags looking for config file: flag: help requested
ERROR: logging before flag.Parse: I0509 10:51:23.862730 1 config.go:256] Default config set
Usage of sloop:
-alsologtostderr
log to standard error as well as files
-apiserver-host string
Kubernetes API server endpoint
-badger-detail-log-enabled
Turns on detailed logging of BadgerDB
-badger-discard-ratio float
Badger value log GC uses this value to decide if it wants to compact a vlog file. The lower the value of discardRatio the higher the number of !badger!move keys. And thus more the number of !badger!move keys, the size on disk keeps on increasing over time. (default 0.99)
-badger-enable-event-logging
Turns on badger event logging
-badger-keep-l0-in-memory
Keeps all level 0 tables in memory for faster writes and compactions (default true)
-badger-level-one-size int
The maximum total size for Level 1. 0 = use badger default
-badger-level-size-multiplier int
The ratio between the maximum sizes of contiguous levels in the LSM. 0 = use badger default
-badger-max-table-size int
Max LSM table size in bytes. 0 = use badger default
-badger-number-of-compactors int
Number of compactors for badger
-badger-number-of-level-zero-tables int
Number of level zero tables for badger
-badger-number-of-zero-tables-stall int
Number of Level 0 tables that once reached causes the DB to stall until compaction succeeds
-badger-sync-writes
Sync Writes ensures writes are synced to disk if set to true (default true)
-badger-use-lsm-only-options
Sets a higher valueThreshold so values would be collocated with LSM tree reducing vlog disk usage (default true)
-badger-vlog-file-size int
Max size in bytes per value log file. 0 = use badger default
-badger-vlog-fileIO-mapping
Indicates which file loading mode should be used for the value log data, in memory constrained environments the value is recommended to be true
-badger-vlog-gc-freq duration
Frequency of running badger's ValueLogGC (default 1m0s)
-badger-vlog-max-entries uint
Max number of entries per value log files. 0 = use badger default (default 200000)
-badger-vlog-truncate
Truncate value log if badger db offset is different from badger db size (default true)
-bind-address string
Web server bind ip address.
-cleanup-frequency duration
Frequency between subsequent runs for the database cleanup (default 30m0s)
-config string
Path to a yaml or json config file
-context string
Use a specific kubernetes context
-cpuprofile string
write profile to file
-crd-refresh-interval duration
Frequency between CRD Informer refresh (default 5m0s)
-default-kind string
Default UX filter kind (default "_all")
-default-lookback string
Default UX filter lookback (default "1h")
-default-namespace string
Default UX filter namespace (default "default")
-deletion-batch-size int
Size of batch for deletion (default 1000)
-disable-kube-watch
Turn off kubernetes watch
-disable-store-manager
Turn off store manager which is to clean up database
-display-context string
Use this to override the display context. When running in k8s the context is empty string. This lets you override that (mainly useful if you are running many copies of sloop on different clusters)
-enable-delete-keys
Use delete prefixes instead of dropPrefix for GC
-gc-threshold float
Threshold for GC to start garbage collecting (default 0.8)
-keep-minor-node-updates
Keep all node updates even if change is only condition timestamps
-kube-watch-resync-interval duration
OPTIONAL: Kubernetes watch resync interval (default 30m0s)
-log_backtrace_at value
when logging hits line file:N, emit a stack trace
-log_dir string
If non-empty, write log files in this directory
-logtostderr
log to standard error instead of files
-max-disk-mb int
Max disk storage in MB (default 32768)
-max-look-back duration
Max history data to keep (default 336h0m0s)
-playback-file string
Read watch data from a playback file
-port int
Web server port (default 8080)
-record-file string
Record watch data to a playback file
-restore-database-file string
Restore database from backup file into current context.
-stderrthreshold value
logs at or above this threshold go to stderr
-store-root string
Path to store history data (default "./data")
-use-mock-badger
Use a fake in-memory mock of badger
-v value
log level for V logs
-vmodule value
comma-separated list of pattern=N settings for file-filtered logging
-watch-crds
Watch for activity for CRDs (default true)
-web-files-path string
Path to web files (default "./pkg/sloop/webserver/webfiles")
修改默認的名稱空間以及資源對象及時間
docker run --rm -it -p 8080:8080 -v ~/.kube/config:/kube/config -e KUBECONFIG=/kube/config sloop sloop -default-namespace=kube-system -default-kind=pod -default-lookback=2h
從源碼安裝
mkdir -p $GOPATH/src/github.com/salesforce
cd $GOPATH/src/github.com/salesforce
git clone https://github.com/salesforce/sloop.git
cd sloop
go env -w GO111MODULE=auto
make
$GOPATH/bin/sloop
Helm 方式安裝
git clone https://github.com/salesforce/sloop.git
cd sloop
cd /root/sloop/helm/sloop
kubectl create namespace sloop
helm template . --namespace sloop> sloop-test.yaml
kubectl -n sloop apply -f sloop-test.yaml
參考:https://github.com/salesforce/sloop.git
k8s 技術圈 專注容器、專注 kubernetes 技術......
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源:https://mp.weixin.qq.com/s/JpdFQHqvuJqS3cDsNYy2Ag