【发布时间】:2020-02-21 23:34:38
【问题描述】:
我已经用 minikube 创建了一个集群
minikube start
应用了这个 yaml 清单:
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway-deployment
spec:
selector:
matchLabels:
app: gateway
replicas: 1
template:
metadata:
labels:
app: gateway
spec:
containers:
- name: gateway
image: docker_gateway
imagePullPolicy: Never
ports:
- containerPort: 4001
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: gateway
spec:
selector:
app: gateway
ports:
- protocol: TCP
port: 4001
而我在容器 docker_gateway 中的 GO 应用只是一个带有一条路由的 gin http 服务器
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/hello", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "hello",
})
})
server = &http.Server{
Addr: ":4001",
Handler: r,
}
server.ListenAndServe()
}
在 Postman 中,我向 192.168.252.130:4001/hello 发出请求并得到响应
但 Kubernetes Pod 在 Kubernetes 中的日志不打印这些请求。我希望得到这个:
[GIN] 2019/10/25 - 14:17:20 | 200 | 1.115µs | 192.168.252.1| GET /hello
但有趣的是 当我添加 Ingress 时
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress
spec:
backend:
serviceName: gateway
servicePort: 4001
我可以向 192.168.252.130/hello 和 192.168.252.130:4001/hello 发出请求 没有端口 Pod 的日志打印请求,但 有端口 - 他们没有。
[GIN] 2019/10/25 - 14:19:13 | 200 | 2.433µs | 192.168.252.1| GET /hello
【问题讨论】:
标签: go kubernetes kubernetes-ingress