在之前的文章中已经介绍了ingress-nginx的部署,本文介绍下怎么使用ingress-nginx去暴露我们的服务
部署服务
apiVersion: apps/v1 kind: Deployment metadata: name: my-httpd spec: replicas: 3 selector: matchLabels: app: myapp template: metadata: labels: app: myapp spec: containers: - name: httpd image: httpd imagePullPolicy: IfNotPresent ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: my-httpd spec: type: ClusterIP selector: app: myapp ports: - port: 80
|
将tomcat的svc添加至ingress-nginx中
apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: my-httpd annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: tomcat.twf.com http: paths: - backend: serviceName: my-httpd servicePort: 80
|
访问
在C:\Windows\System32\drivers\etc\hosts 添加一行 192.168.70.128 tomcat.twf.com ,ip和域名根据自己的ip修改
浏览器访问 http://tomcat.twf.com:32080/
