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

Podinfo, mini go microservice template

2021-01-23 16:37:30 For less

​ Project introduction

Podinfo It's a use. Go Make small web Applications , It shows that in Kubernetes Best practices for running 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 accelerated mirror image

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

To write Dockerfile.dev file

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

structure Image

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

To 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 button start

docker-compose up

Run Remote Docker

View home page

http://localhost:9898

View to Prometheus Of  metrics API

http://localhost:9898/metrics

Lower breakpoint , 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 Experience .

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 , understand PodInfo How to get to the cloud ?

It's worth learning from

Parameters The default value is describe
replicaCount 1 Expectant K8S Pods( That is, the code deploys several instances in the cluster )
logLevel info

The level of logging :

 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 Open or not Redis cache
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 libraries ( Address )
image.tag <VERSION> Mirror 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 Index endpoint port
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 End point's NodePort
hpa.enabled false

Enable Kubernetes HPA

(Pod Horizontal auto retraction )

hpa.maxReplicas 10 Pods The largest number
hpa.cpu None Every Pod The goal of CPU Usage rate
hpa.memory None Every Pod Target memory usage of
hpa.requests None Every Pod Target per second HTTP request
serviceAccount.enabled false Should I create service account
serviceAccount.name None To be used service account The name of , If not set and enabled by true, Then use fullname Generate name
linkerd.profile.enabled false establish Linkerd Service profile
serviceMonitor.enabled false Should I create Prometheus Operator Service Monitor
serviceMonitor.interval 15s Prometheus Grab interval
ingress.enabled false Enable Ingress
ingress.annotations {} Ingress annotation
ingress.path /* Ingress route
ingress.hosts [] Ingress Accepted hosts
ingress.tls [] Ingress TLS To configure
resources.requests.cpu 1m Pod CPU request
resources.requests.memory 16Mi Pod Memory request
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 annotation

Refs

The author has revised Podinfo Project address

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

official  Podinfo

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

 

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