podinfo
Podinfo is a tiny web application made with Go that showcases best practices of running microservices in Kubernetes.
Podinfo is used by CNCF projects like Flux and Flagger
for end-to-end testing and workshops.
Specifications:
- Health checks (readiness and liveness)
- Graceful shutdown on interrupt signals
- File watcher for secrets and configmaps
- Instrumented with Prometheus and Open Telemetry
- Structured logging with zap
- 12-factor app with viper
- Fault injection (random errors and latency)
- Swagger docs
- Timoni, Helm and Kustomize installers
- End-to-End testing with Kubernetes Kind and Helm
- Multi-arch container image with Docker buildx and Github Actions
- Container image signing with Sigstore cosign
- SBOMs and SLSA Provenance embedded in the container image
- CVE scanning with Trivy
Web API:
GET /
prints runtime information
GET /version
prints podinfo version and git commit hash
GET /metrics
return HTTP requests duration and Go runtime metrics
GET /healthz
used by Kubernetes liveness probe
GET /readyz
used by Kubernetes readiness probe
POST /readyz/enable
signals the Kubernetes LB that this instance is ready to receive traffic
POST /readyz/disable
signals the Kubernetes LB to stop sending requests to this instance
GET /status/{code}
returns the status code
GET /panic
crashes the process with exit code 255
POST /echo
forwards the call to the backend service and echos the posted content
GET /env
returns the environment variables as a JSON array
GET /headers
returns a JSON with the request HTTP headers
GET /delay/{seconds}
waits for the specified period
POST /token
issues a JWT token valid for one minute JWT=$(curl -sd 'anon' podinfo:9898/token | jq -r .token)
GET /token/validate
validates the JWT token curl -H "Authorization: Bearer $JWT" podinfo:9898/token/validate
GET /configs
returns a JSON with configmaps and/or secrets mounted in the config
volume
POST/PUT /cache/{key}
saves the posted content to Redis
GET /cache/{key}
returns the content from Redis if the key exists
DELETE /cache/{key}
deletes the key from Redis if exists
POST /store
writes the posted content to disk at /data/hash and returns the SHA1 hash of the content
GET /store/{hash}
returns the content of the file /data/hash if exists
GET /ws/echo
echos content via websockets podcli ws ws://localhost:9898/ws/echo
GET /chunked/{seconds}
uses transfer-encoding
type chunked
to give a partial response and then waits for the specified period
GET /swagger.json
returns the API Swagger docs, used for Linkerd service profiling and Gloo routes discovery
gRPC API:
/grpc.health.v1.Health/Check
health checking
Web UI:
To access the Swagger UI open <podinfo-host>/swagger/index.html
in a browser.
Guides
Install
To install Podinfo on Kubernetes the minimum required version is Kubernetes v1.23.
Timoni
Install with Timoni:
timoni -n default apply podinfo oci://ghcr.io/stefanprodan/modules/podinfo
Helm
Install from github.io:
helm repo add podinfo https://stefanprodan.github.io/podinfo
helm upgrade --install --wait frontend \
--namespace test \
--set replicaCount=2 \
--set backend=http://backend-podinfo:9898/echo \
podinfo/podinfo
helm test frontend --namespace test
helm upgrade --install --wait backend \
--namespace test \
--set redis.enabled=true \
podinfo/podinfo
Install from ghcr.io:
helm upgrade --install --wait podinfo --namespace default \
oci://ghcr.io/stefanprodan/charts/podinfo
Kustomize
kubectl apply -k gitee.com/fpy-go/plugin//kustomize
Docker
docker run -dp 9898:9898 stefanprodan/podinfo
Continuous Delivery
In order to install podinfo on a Kubernetes cluster and keep it up to date with the latest
release in an automated manner, you can use Flux.
Install the Flux CLI on MacOS and Linux using Homebrew:
brew install fluxcd/tap/flux
Install the Flux controllers needed for Helm operations:
flux install \
--namespace=flux-system \
--network-policy=false \
--components=source-controller,helm-controller
Add podinfo's Helm repository to your cluster and
configure Flux to check for new chart releases every ten minutes:
flux create source helm podinfo \
--namespace=default \
--url=https://stefanprodan.github.io/podinfo \
--interval=10m
Create a podinfo-values.yaml
file locally:
cat > podinfo-values.yaml <<EOL
replicaCount: 2
resources:
limits:
memory: 256Mi
requests:
cpu: 100m
memory: 64Mi
EOL
Create a Helm release for deploying podinfo in the default namespace:
flux create helmrelease podinfo \
--namespace=default \
--source=HelmRepository/podinfo \
--release-name=podinfo \
--chart=podinfo \
--chart-version=">5.0.0" \
--values=podinfo-values.yaml
Based on the above definition, Flux will upgrade the release automatically
when a new version of podinfo is released. If the upgrade fails, Flux
can rollback
to the previous working version.
You can check what version is currently deployed with:
flux get helmreleases -n default
To delete podinfo's Helm repository and release from your cluster run:
flux -n default delete source helm podinfo
flux -n default delete helmrelease podinfo
If you wish to manage the lifecycle of your applications in a GitOps manner, check out
this workflow example
for multi-env deployments with Flux, Kustomize and Helm.
NOTICE
插件命名规范
protocol-grpc/rpc-xxx
在重新加载插件之前比做事项
必须调用manager的kill方法,关闭client和server的连接,并关闭server服务,否则删除对应的插件文件会失败
基于云原生的场景,我们其实可以不把插件放到minio等网络存储中,直接本地存储更高效
原因在于:云原生下使用pv来共享目录,多个pod公用共一个pv,再加上路径监听,就可以实现多个pod的插件加载
client启动时我们如何监听到server服务端口的
可以参考go-plugin的client和server类,里面通过stdout来读取server的ip和端口
如果server意外终止
插件调用会返回err:connection is shut down
这时候我们要做处理,提示或者日志记录
如果client连接意外终止
插件调用会返回err:connection is shut down
这时候我们要做处理,提示或者日志记录
go-plugin的rpc_client使用gob(非json)包实现的序列化和反序列化
所以我们在使用的时候要注册声明的对象到gob中,参考sagoomqtt.go
对于插件的Encode和Decode方法的参数,如果指定了类型,则没问题,如果使用interface{},则需要把实际的参数类型注册到gob中
例如Decode(args interface{})方法,传参是Dog类型,那么Dog类型就必须在插件中Register
grpc
PluginClient -- Broker -- brokerID -- con -- PluginServer