ingress-nginx
ingress 官方网站
ingress 仓库地址
ingress-nginx v1.1 最新版本 v1.1
适用于Kubernetes 版本 v1.19+ (也包括 v1.19 )
Kubernetes-v1.22+ 需要使用 ingress-nginx>=1.0,因为 networking.k8s.io/v1beta 已经移除
直接部署 ingress-nginx
直接部署比较简单,直接拉去 github
的文件就可以了,如果遇到长时间无响应,可以终止任务从新拉取。
拉取镜像部分,可以修改为一下的镜像地址
$ wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/baremetal/deploy.yaml
$ sed -i 's@k8s.gcr.io/ingress-nginx/controller:v1.1.0\(.*\)@willdockerhub/ingress-nginx-controller:v1.1.0@' deploy.yaml
$ sed -i 's@k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1\(.*\)$@hzde0128/kube-webhook-certgen:v1.1@' deploy.yaml
$ kubectl apply -f ingress-nginx.yaml
检查ingress-nginx 状态
$ kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-shjt6 0/1 Completed 0 107m
ingress-nginx-admission-patch-qt2cv 0/1 Completed 0 107m
ingress-nginx-controller-689b7bb46c-j5stp 1/1 Running 0 107m
$ kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.96.186.13 <none> 80:32081/TCP,443:32540/TCP 107m
ingress-nginx-controller-admission ClusterIP 10.96.55.31 <none> 443/TCP 107m
测试部署ingress-nginx
# vim nginx-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: nginx.test.com
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
#声明部署nginx-ingress
$ kubectl apply -f nginx-ingress.yaml
#查看ingress-nginx 节点对应的端口
$ kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.96.186.13 <none> 80:32081/TCP,443:32540/TCP 107m
ingress-nginx-controller-admission ClusterIP 10.96.55.31 <none> 443/TCP 107m
访问ingress映射的域名暴露的端口
# curl nginx.test.com:32081
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>