Podinfo 是一個用 Go 製做的小型 web 應用程序,它展現了在 Kubernetes 中運行微服務的最佳實踐。node
它已實現的技術指標(截選自官方 README.md ):git
裏面每一項技術指標的實現方式,其實均可以拿出來單獨講很久,相關理論也有好多。github
這裏我只是講針對這個項目,咱們該如何使用 Docker 去試玩它。golang
VSCode + golang/vscode-goweb
https://learnku.com/go/wikis/38122redis
FROM golang:1.14
WORKDIR /workspace
# copy modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# 阿里雲
RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
# cache modules
RUN go mod download
RUN go get github.com/go-delve/delve/cmd/dlv
docker build -f Dockerfile.dev -t podinfo:dev .
version: "3.4"
services:
golang:
image: podinfo:dev
command: >
bash -c "ls -la
&& dlv debug /workspace/cmd/podinfo --headless --log -l 0.0.0.0:2345 --api-version=2"
volumes:
- ./:/workspace
ports:
- 9898:9898
- 2345:2345
security_opt:
- "seccomp:unconfined"
.vscode
的 launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Remote Docker",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath":"/workspace",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceFolder}",
"args": [],
"trace" : "verbose",
"env" : {}
}
]
}
docker-compose up
http://localhost:9898docker
metrics
APIhttp://localhost:9898/metricsjson
curl http://localhost:9898/api/info
Podinfo/Charts後端
https://github.com/stefanprodan/podinfo/tree/master/charts/podinfoapi
由於 Podinfo 是一個雲原生項目,因此它的 Helm Charts 的編寫仍是值得借鑑和學習的。
固然這裏須要你有一些 K8S 的經驗。
$ helm repo add podinfo https://stefanprodan.github.io/podinfo
$ helm upgrade -i my-release podinfo/podinfo
$ helm delete my-release
很是值得借鑑
參數 | 默認值 | 描述 |
---|---|---|
replicaCount |
1 |
指望的 K8S Pods(也就是代碼在集羣中部署幾個實例) |
logLevel |
info |
日誌級別: or |
backend |
None |
須要調用的後端或者是第三方的 URL(如 Java 後端) |
backends |
[] |
須要調用的後端或者是第三方的 URLs(如 Java 後端) |
cache |
None |
Redis 地址 <host>:<port> |
redis.enabled |
false |
是否開啓 Redis 緩存 |
ui.color |
#34577c |
UI 顏色 |
ui.message |
None |
UI 問候消息 |
ui.logo |
None |
UI logo |
faults.delay |
false |
隨機 HTTP 響應延遲 0 到 5 秒 |
faults.error |
false |
1/3 機率的隨機 HTTP 響應錯誤 |
faults.unhealthy |
false |
設置後,永遠不會達到健康狀態 |
faults.unready |
false |
當設置時,永遠不會達到就緒狀態 |
faults.testFail |
false |
當設置時,helm 測試老是失敗 |
faults.testTimeout |
false |
當設置時,helm 測試老是包括超時 |
h2c.enabled |
false |
容許升級到 h2c |
image.repository |
stefanprodan/podinfo |
鏡像庫(地址) |
image.tag |
<VERSION> |
鏡像 tag |
image.pullPolicy |
IfNotPresent |
Image 拉取策略 |
service.enabled |
true |
建立 Kubernetes 服務,使用 Flagger 時應禁用 |
service.type |
ClusterIP |
Kubernetes Service 類型 |
service.metricsPort |
9797 |
Prometheus 指標端點端口 |
service.httpPort |
9898 |
Container HTTP 端口 |
service.externalPort |
9898 |
ClusterIP HTTP 端口 |
service.grpcPort |
9999 |
ClusterIP gPRC 端口 |
service.grpcService |
podinfo |
gPRC service 名稱 |
service.nodePort |
31198 |
HTTP 端點的 NodePort |
hpa.enabled |
false |
啓用 Kubernetes HPA (Pod 水平自動伸縮) |
hpa.maxReplicas |
10 |
Pods 最大數量 |
hpa.cpu |
None |
每一個 Pod 的目標CPU使用率 |
hpa.memory |
None |
每一個 Pod 的目標內存使用量 |
hpa.requests |
None |
每一個 Pod 每秒目標 HTTP 請求 |
serviceAccount.enabled |
false |
是否應建立 service account |
serviceAccount.name |
None |
要使用的 service account 的名稱,若是未設置且 enabled 爲true,則使用 fullname 生成名稱 |
linkerd.profile.enabled |
false |
建立 Linkerd 服務配置文件 |
serviceMonitor.enabled |
false |
是否應建立 Prometheus Operator 服務監視器 |
serviceMonitor.interval |
15s |
Prometheus 抓取間隔 |
ingress.enabled |
false |
啓用 Ingress |
ingress.annotations |
{} |
Ingress 註解 |
ingress.path |
/* |
Ingress 路徑 |
ingress.hosts |
[] |
Ingress 接受的 hosts |
ingress.tls |
[] |
Ingress TLS 配置 |
resources.requests.cpu |
1m |
Pod CPU 請求 |
resources.requests.memory |
16Mi |
Pod 內存 請求 |
resources.limits.cpu |
None |
Pod CPU 限制 |
resources.limits.memory |
None |
Pod memory 限制 |
nodeSelector |
{} |
Pod 分配的集羣節點標籤(說白了就是固定部署到你指定的機器) |
tolerations |
[] |
可容忍的節點污點列表 |
affinity |
None |
Node/pod 親和力 |
podAnnotations |
{} |
Pod 註解 |
https://github.com/Hacker-Linner/podinfo
官方 Podinfo
https://github.com/stefanprodan/podinfo
我是爲少。
微信:uuhells123。公衆號:黑客下午茶。謝謝點贊支持👍👍👍!