当前位置:网站首页>Podinfo, mini go microservice template

Podinfo, mini go microservice template

2021-01-23 23:25:26 itread01

​ Project introduction

Podinfo It's a use Go Make small web Applications , It shows that in Kubernetes Best practices for executing microservices in .

It has achieved the technical indicators ( Excerpt from the official README.md ):

How to realize every technical index in it , In fact, we can talk about it alone for a long time , There are many related theories .

I'm just talking about this project , How do we use Docker Try it out .

Build a container debugging environment

IDE

VSCode + golang/vscode-go

Go Domestic acceleration image

https://learnku.com/go/wikis/38122

Write Dockerfile.dev Archives

FROM golang:1.14

WORKDIR /workspace

# copy modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# Alibaba cloud
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

Build Image

docker build -f Dockerfile.dev -t podinfo:dev .

Write docker-compose.yaml

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"

To configure  .vscode  Of  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" : {}
}
]
}

Start playing

docker compose One click Start

docker-compose up

Run Remote Docker

View the home page

http://localhost:9898

View to Prometheus Of  metrics API

http://localhost:9898/metrics

Break point , Send a request to debug

curl http://localhost:9898/api/info

Helm Charts 

Podinfo/Charts

  • https://github.com/stefanprodan/podinfo/tree/master/charts/podinfo

Because Podinfo It's a cloud native project , So it's Helm Charts It is worth learning and learning from .

Of course, you need to have some K8S The experience of .

Helm Install Podinfo

$ helm repo add podinfo https://stefanprodan.github.io/podinfo

$ helm upgrade -i my-release podinfo/podinfo

Helm Uninstall Podinfo

$ helm delete my-release

See configuration , Understanding PodInfo How to get to the cloud ?

It's worth learning from

Arguments Default value describe
replicaCount 1 Expectant K8S Pods( That is, the code deploys several examples in the cluster )
logLevel info

Log level :

 debuginfowarnerrorflat 

or panic

backend None The back end that needs to be called or the third party URL( Such as Java back-end )
backends [] The back end that needs to be called or the third party URLs( Such as Java back-end )
cache None Redis Address  <host>:<port>
redis.enabled false Whether to open Redis Get it
ui.color #34577c UI Color
ui.message None UI Greeting message
ui.logo None UI logo
faults.delay false Random HTTP Response delay 0 To 5 second
faults.error false 1/3 The randomness of probability HTTP Response error
faults.unhealthy false After setting , Never reach a healthy state
faults.unready false When setting , Never get ready
faults.testFail false When setting ,helm Tests always fail
faults.testTimeout false When setting ,helm Tests always include timeouts
h2c.enabled false Allow upgrade to h2c
image.repository stefanprodan/podinfo Image library ( Address )
image.tag <VERSION> The image tag
image.pullPolicy IfNotPresent Image Pull strategy
service.enabled true establish Kubernetes Service , Use  Flagger  It should be disabled
service.type ClusterIP Kubernetes Service Type
service.metricsPort 9797 Prometheus The indicators are
service.httpPort 9898 Container HTTP Port
service.externalPort 9898 ClusterIP HTTP Port
service.grpcPort 9999 ClusterIP gPRC Port
service.grpcService podinfo gPRC service Name
service.nodePort 31198 HTTP The endpoint of NodePort
hpa.enabled false

Enable Kubernetes HPA

(Pod Horizontal auto retraction )

hpa.maxReplicas 10 Pods The maximum number
hpa.cpu None Every Pod Goal of CPU Usage rate
hpa.memory None Every Pod Target memory usage of
hpa.requests None Every Pod Target per second HTTP Ask for
serviceAccount.enabled false Should we establish service account
serviceAccount.name None To be used service account The name of , If not set and enabled For true, Use fullname Build name
linkerd.profile.enabled false establish Linkerd Service configuration profile
serviceMonitor.enabled false Should we establish Prometheus Operator Service Monitor
serviceMonitor.interval 15s Prometheus Grab interval
ingress.enabled false Enable Ingress
ingress.annotations {} Ingress Notes
ingress.path /* Ingress Path
ingress.hosts [] Ingress Accepted hosts
ingress.tls [] Ingress TLS To configure
resources.requests.cpu 1m Pod CPU Ask for
resources.requests.memory 16Mi Pod Memory Ask for
resources.limits.cpu None Pod CPU Limit
resources.limits.memory None Pod memory Limit
nodeSelector {} Pod Assigned cluster node label ( To put it bluntly, it is a fixed deployment to your designated machine )
tolerations [] List of tolerable node taints
affinity None Node/pod Affinity
podAnnotations {} Pod Notes

Refs

The author has revised Podinfo Project address

  • https://github.com/Hacker-Linner/podinfo

official  Podinfo

  • https://github.com/stefanprodan/podinfo

 

I'm for less .

WeChat :uuhells123.
Public number : Hacker afternoon tea .
Thank you for your support

版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/01/20210123232234580Z.html

随机推荐