• 欢迎光临~

Ingress

开发技术 开发技术 2022-07-21 次浏览

https://blog.csdn.net/qq_43539962/article/details/118161898?spm=1001.2014.3001.5502

https://blog.csdn.net/weixin_44953658/article/details/116976385

 https://blog.csdn.net/demon_xi/article/details/119698628
1.安装
2.检查安装
kubectl get pod -n ingress-nginx kubectl get svc -n ingress-nginx
Ingress
3.创建pod和service进行验证
Ingress
  • 创建tomcat-nginx.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
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

 

  • 创建Service和Pod:
kubectl create -f tomcat-nginx.yaml
Ingress
  • 查看Service和Pod:
kubectl get svc,pod -n dev
Ingress
4. HTTP代理
  • 创建ingress-http.yaml文件,内容如下:
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-http namespace: dev spec: rules: - host: nginx.xudaxian.com http: paths: - path: / backend: serviceName: nginx-service servicePort: 80 - host: tomcat.xudaxian.com http: paths: - path: / backend: serviceName: tomcat-service servicePort: 8080
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-http
  namespace: dev
spec:
  rules:
  - host: nginx.xudaxian.com
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx-service
          servicePort: 80
  - host: tomcat.xudaxian.com
    http:
      paths:
      - path: /
        backend:
          serviceName: tomcat-service
          servicePort: 8080

 

  • 创建:
kubectl create -f ingress-http.yaml
Ingress
  • 查看:
kubectl get ingress ingress-http -n dev
Ingress
  • 查看详情:
kubectl describe ingress ingress-http -n dev
Ingress
  • 在本机的hosts文件中添加如下的规则(192.168.209.100为Master节点的IP地址):
192.168.209.100 nginx.xudaxian.com 192.168.209.100 tomcat.xudaxian.com
  • 查看ingress-nginx的端口(本次测试http的端口是30378,https的端口是31125):
kubectl get svc -n ingress-nginx
Ingress
  • 本机通过浏览器输入下面的地址访问:
http://nginx.xudaxian.com:30378 http://tomcat.xudaxian.com:30378
 
 
 
程序员灯塔
转载请注明原文链接:Ingress
喜欢 (0)