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-deployment
- namespace: dev
- spec:
- replicas: 3
- selector:
- matchLabels:
- app: nginx-pod
- template:
- metadata:
- labels:
- app: nginx-pod
- spec:
- containers:
- - name: nginx
- image: nginx:1.17.1
- ports:
- - containerPort: 80
- ---
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- name: tomcat-deployment
- namespace: dev
- spec:
- replicas: 3
- selector:
- matchLabels:
- app: tomcat-pod
- template:
- metadata:
- labels:
- app: tomcat-pod
- spec:
- containers:
- - name: tomcat
- image: tomcat:8.5-jre10-slim
- ports:
- - containerPort: 8080
- ---
- apiVersion: v1
- kind: Service
- metadata:
- name: nginx-service
- namespace: dev
- spec:
- selector:
- app: nginx-pod
- clusterIP: None
- type: ClusterIP
- ports:
- - port: 80
- targetPort: 80
- ---
- apiVersion: v1
- kind: Service
- metadata:
- name: tomcat-service
- namespace: dev
- spec:
- selector:
- app: tomcat-pod
- clusterIP: None
- type: ClusterIP
- ports:
- - port: 8080
- targetPort: 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-http
- namespace: dev
- spec:
- rules:
- - host: nginx.wzq.com
- http:
- paths:
- - backend:
- service:
- name: nginx-service
- port:
- number: 80
- path: /
- 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>
复制代码 部署乐成
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |