ingress的故障排查方法
参考:
https://kubernetes.github.io/ingress-nginx/troubleshooting/
https://kubernetes.github.io/ingress-nginx/kubectl-plugin/
注意:
ingress-nginx插件在修改部署方式为daemonset后,无法使用
拓展:ingress-nginx插件
1,首先我们来看下ingress-nginx的插件输出。以bankend为例子
kubectl ingress-nginx backends -n ingress-nginx
[
{
"name": "default-apple-service-5678",
"service": {
"metadata": {
"creationTimestamp": null
},
"spec": {
"ports": [
{
"protocol": "TCP",
"port": 5678,
"targetPort": 5678
}
],
"selector": {
"app": "apple"
},
"clusterIP": "10.97.230.121",
"type": "ClusterIP",
"sessionAffinity": "None"
},
"status": {
"loadBalancer": {}
}
},
"port": 0,
"secureCACert": {
"secret": "",
"caFilename": "",
"pemSha": ""
},
"sslPassthrough": false,
"endpoints": [
{
"address": "10.1.3.86",
"port": "5678"
}
],
"sessionAffinityConfig": {
"name": "",
"cookieSessionAffinity": {
"name": ""
}
},
"upstreamHashByConfig": {
"upstream-hash-by-subset-size": 3
},
"noServer": false,
"trafficShapingPolicy": {
"weight": 0,
"header": "",
"headerValue": "",
"cookie": ""
}
},
{
"name": "default-echo-service-8080",
...
},
{
"name": "upstream-default-backend",
...
}
]
2,我们看下插件目录的结构
[root@k8s-master-01.novalocal 14:41 ~/.krew]
# ls -lt
total 0
drwxr-xr-x. 2 root root 55 Jul 9 12:28 bin
drwxr-xr-x. 4 root root 39 Jul 9 12:28 store
drwxr-xr-x. 5 root root 209 Jul 9 12:28 index
- bin为命令所在目录
- store为命令软连接
- index为配置元文件
3,查看ingress-nginx配置
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: ingress-nginx
spec:
shortDescription: Interact with ingress-nginx
description: |
The official kubectl plugin for ingress-nginx.
version: 0.24.0
homepage: https://kubernetes.github.io/ingress-nginx/kubectl-plugin/
platforms:
- uri: https://github.com/kubernetes/ingress-nginx/releases/download/nginx-0.24.0/kubectl-ingress_nginx-darwin-amd64.tar.gz
sha256: 34e999ddc4e1926bbd7f4bdbb5fc40d6c3a5b2ffd711131e4f62e2d24cb2a179
files:
- from: "*"
to: "."
bin: "./kubectl-ingress_nginx"
selector:
matchLabels:
os: darwin
arch: amd64
- uri: https://github.com/kubernetes/ingress-nginx/releases/download/nginx-0.24.0/kubectl-ingress_nginx-linux-amd64.tar.gz
sha256: 05d48fe58faa0ff577fe3b9c90f2e21233a140712a9f9ff0c9bd867e65f1b4e5
files:
- from: "*"
to: "."
bin: "./kubectl-ingress_nginx"
selector:
matchLabels:
os: linux
arch: amd64
4,查看命令源码
在cmd/plugin/main.go
rootCmd.AddCommand(backends.CreateCommand(flags))
查看具体的backends。实际 是登录到pod中然后执行了相关的命令
在cmd/plugin/commands/backends/backends.go
func backends(flags *genericclioptions.ConfigFlags, podName string, deployment string, backend string, onlyList bool) error {
var command []string
if onlyList {
command = []string{"/dbg", "backends", "list"}
} else if backend != "" {
command = []string{"/dbg", "backends", "get", backend}
} else {
command = []string{"/dbg", "backends", "all"}
}
pod, err := request.ChoosePod(flags, podName, deployment)
if err != nil {
return err
}
out, err := kubectl.PodExecString(flags, &pod, command)
if err != nil {
return err
}
fmt.Print(out)
return nil
}
执行命令可能为
- /dbg backends list
- /dbg backends get xxx
- /dbg backends all