您的位置:首页 > 新闻 > 会展 > kubernetes之安装ingress-nginx(k8s1.19版本之后)

kubernetes之安装ingress-nginx(k8s1.19版本之后)

2025/1/12 1:33:09 来源:https://blog.csdn.net/weixin_44946147/article/details/139420499  浏览:    关键词:kubernetes之安装ingress-nginx(k8s1.19版本之后)

ingress-nginx

    • 1. 项目地址
    • 2. 操作环节
    • 3. 测试
        • 3.1 部署nginx及tomcat
        • 3.2 部署ingress

1. 项目地址

ingress-nginx项目地址

2. 操作环节

root@master1:~# kubectl apply -f nginx-ingress-controller/manifests/root@master1:~# kubectl get pods -n ingress-nginx 
NAME                                        READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-w768p        0/1     Completed   0          63m
ingress-nginx-admission-patch-hgrhz         0/1     Completed   2          63m
ingress-nginx-controller-85858f5dc4-xvzgd   1/1     Running     0          63m

3. 测试

3.1 部署nginx及tomcat

编写tomcat-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deploymentnamespace: dev
spec:replicas: 3selector:matchLabels:app: nginx-podtemplate:metadata:labels:app: nginx-podspec:containers:- name: nginximage: nginx:1.17.1ports:- containerPort: 80---apiVersion: apps/v1
kind: Deployment
metadata:name: tomcat-deploymentnamespace: dev
spec:replicas: 3selector:matchLabels:app: tomcat-podtemplate:metadata:labels:app: tomcat-podspec:containers:- name: tomcatimage: tomcat:8.5-jre10-slimports:- containerPort: 8080---apiVersion: v1
kind: Service
metadata:name: nginx-servicenamespace: dev
spec:selector:app: nginx-podclusterIP: Nonetype: ClusterIPports:- port: 80targetPort: 80---apiVersion: v1
kind: Service
metadata:name: tomcat-servicenamespace: dev
spec:selector:app: tomcat-podclusterIP: Nonetype: ClusterIPports:- port: 8080targetPort: 8080

部署

root@master1:~/yaml# kubectl apply -f tomcat-deploy.yaml

查看

root@master1:~/yaml# kubectl get pods -n dev
NAME                                 READY   STATUS    RESTARTS   AGE
nginx-deployment-5cb65f68db-52dk6    1/1     Running   0          89m
nginx-deployment-5cb65f68db-74fc2    1/1     Running   0          89m
nginx-deployment-5cb65f68db-8f966    1/1     Running   0          89m
tomcat-deployment-7ff7bd5bcd-4c6x9   1/1     Running   0          89m
tomcat-deployment-7ff7bd5bcd-5phbh   1/1     Running   0          89m
tomcat-deployment-7ff7bd5bcd-m27tf   1/1     Running   0          89m

这里看到 已经成功部署测试用的tomecat及nginx

3.2 部署ingress

通过kubectl api-resources | grep ingress查看到ingress的版本是 networking.k8s.io/v1

部署ingress-http.com

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: ingress-httpnamespace: dev
spec:rules:- host: nginx.wzq.comhttp:paths:- backend:service: name: nginx-serviceport:number: 80path: /pathType: Prefix
root@master1:~/yaml# kubectl get ingress -n dev
NAME           CLASS    HOSTS           ADDRESS   PORTS   AGE
ingress-http   <none>   nginx.wzq.com             80      49m
root@master1:~/yaml# kubectl describe ingress -n dev
Name:             ingress-http
Labels:           <none>
Namespace:        dev
Address:          
Ingress Class:    <none>
Default backend:  <default>
Rules:Host           Path  Backends----           ----  --------nginx.wzq.com  /   nginx-service:80 (10.244.1.26:80,10.244.1.27:80,10.244.2.36:80)
Annotations:     <none>
Events:          <none>

部署成功

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com