Ingress Nginx
简介
这个组件由 Nginx Ingress Controller 项目官方提供,可以在控制台和 Nginx Ingress Controller 进行交互。
基本用法
安装 Nginx Ingress Controller
# 部署 Deployment
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
namespace/ingress-nginx configured
configmap/nginx-configuration created
...
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
service/ingress-nginx created
查看 Ingress 后端服务
kubectl ingress-nginx backends
[
{
"name": "upstream-default-backend",
"port": 0,
"secureCACert": {
"secret": "",
"caFilename": "",
"pemSha": ""
},
"sslPassthrough": false,
"endpoints": [
{
"address": "127.0.0.1",
"port": "8181"
}
],
"sessionAffinityConfig": {
"name": "",
"cookieSessionAffinity": {
"name": ""
}
},
"upstreamHashByConfig": {},
"noServer": false,
"trafficShapingPolicy": {
"weight": 0,
"header": "",
"headerValue": "",
"cookie": ""
}
}
]
列出当前的 Ingress 资源
这个功能和 kubectl get ing -o wide
类似:
$ kubectl ingress-nginx ingresses
INGRESS NAME HOST+PATH ADDRESSES TLS SERVICE SERVICE PORT ENDPOINTS
flask flask.whitehorse.com/ 139.67.22.123 YES flaskapp 80 2
flaskapp flaskapp.whitehorse.com/ 139.67.22.123 NO flaskapp 80 2
$ kubectl get ingress -o wide
NAME HOSTS ADDRESS PORTS AGE
flask flask.whitehorse.com 139.67.22.123 80, 443 129m
flaskapp flaskapp.whitehorse.com 139.67.22.123 80 152m
获取当前 Ingress Controller 的运行配置
$ kubectl ingress-nginx conf
# Configuration checksum: 17417893439548704315
# setup custom paths that do not require root access
pid /tmp/nginx.pid;
load_module /etc/nginx/modules/ngx_http_modsecurity_module.so;
daemon off;
worker_processes 2;
...
其它几个有用的命令
获取特定主机名所使用的 TLS 证书:
kubectl ingress-nginx certs --host flask.whitehorse.com
读取 Ingress 日志:
kubectl ingress-nginx logs
Ingress Controller 信息:
kubectl ingress-nginx general
kubectl ingress-nginx info
参考链接
- Nginx Ingress Controller:
https://kubernetes.github.io/ingress-nginx/deploy