Kong gateway health check配置方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kong gateway health check配置方法相关的知识,希望对你有一定的参考价值。
参考技术A 随着微服务越来越火,对于如何对微服务进行健康检查,也出现了很多成熟的解决方案。本文以其中应用较多的Kong gateway为例,详细讲述如何配置kong health check。Kong有两种健康检查方法,可分别或同时使用:
active checks主动检查,其中定期请求目标中的特定HTTP或HTTPS端点,并根据其响应确定目标的健康状态;
passive checks被动检查(也称为断路器),Kong在其中分析正在代理的流量,并根据目标的行为响应请求来确定目标的健康状况。
配置health check有两种方式,一种通过kong admin api直接配置(参考官方文档),另一种可以通过配置KongIngress的方式来实现。本文主要介绍后一种方式。
配置KongIngress:
配置完成后,可以通过kubectl get kongingress来查看。要想让这个配置生效,还需要绑定到对应service上,方法如下:
在对应service的yaml文件中增加标红部分,之后只要正常部署即可。
最后,可以通过kong admin api来查看效果:
观察到标红处为"HEALTHY"或者"UNHEALTHY"配置就生效了。如果观察到"HEALTHYCHECK_OFF"那就是配置没有生效,需要具体查看原因。
linux 安装kong gateway
-
Create a Docker network
You will need to create a custom network to allow the containers to discover and communicate with each other. In this example
kong-net
is the network name, you can use any name.$ docker network create kong-net
-
Start your database
If you wish to use a Cassandra container:
$ docker run -d --name kong-database \\ --network=kong-net \\ -p 9042:9042 \\ cassandra:3
If you wish to use a PostgreSQL container:
$ docker run -d --name kong-database \\ --network=kong-net \\ -p 5432:5432 \\ -e "POSTGRES_USER=kong" \\ -e "POSTGRES_DB=kong" \\ postgres:9.6
-
Prepare your database
Run the migrations with an ephemeral Kong container:
$ docker run --rm \\ --network=kong-net \\ -e "KONG_DATABASE=postgres" \\ -e "KONG_PG_HOST=kong-database" \\ -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \\ kong:latest kong migrations up
In the above example, both Cassandra and PostgreSQL are configured, but you should update the
KONG_DATABASE
environment variable with eithercassandra
orpostgres
.Note: migrations should never be run concurrently; only one Kong node should be performing migrations at a time.
-
Start Kong
When the migrations have run and your database is ready, start a Kong container that will connect to your database container, just like the ephemeral migrations container:
$ docker run -d --name kong \\ --network=kong-net \\ -e "KONG_DATABASE=postgres" \\ -e "KONG_PG_HOST=kong-database" \\ -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \\ -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \\ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \\ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \\ -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \\ -e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \\ -p 8000:8000 \\ -p 8443:8443 \\ -p 8001:8001 \\ -p 8444:8444 \\ kong:0.13.1-centos
-
Use Kong
Kong is running:
$ curl -i http://localhost:8001/
Using Docker
# Start Kong Dashboard
docker run --rm -p 8080:8080 pgbi/kong-dashboard start --kong-url http://kong:8001
# Start Kong Dashboard on a custom port
docker run --rm -p [port]:8080 pgbi/kong-dashboard start --kong-url http://kong:8001
# Start Kong Dashboard with basic auth
docker run --rm -p 8080:8080 pgbi/kong-dashboard start \\
--kong-url http://kong:8001 \\
--basic-auth user1=password1 user2=password2
# See full list of start options
docker run --rm -p 8080:8080 pgbi/kong-dashboard start --help
- Create bridge network
docker network create my-net
- Add Kong container to it
docker network connect my-net kong
- Provide network info when you run kong-dashboard
docker run --rm --network my-net -p 8080:8080 pgbi/kong-dashboard start --kong-url http://kong:8001
以上是关于Kong gateway health check配置方法的主要内容,如果未能解决你的问题,请参考以下文章