k8s- nginx ingress 高可用部署(最新版,支持 k8s 1.22---1.19)第3篇 测试

k8s的master节点上创建一个pod,和ingress. yaml文件如下:

apiVersion: v1
kind: Service
metadata:
  name: tomcat
  namespace: default
spec:
  selector:
    app: tomcat
    release: canary
  ports:
  - name: http
    targetPort: 8080
    port: 8080
  - name: ajp
    targetPort: 8009
    port: 8009
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deploy
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: tomcat
      release: canary
  template:
    metadata:
      labels:
        app: tomcat
        release: canary
    spec:
      containers:
      - name: tomcat
        image: tomcat:8.5.34-jre8-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 8080
          name: ajp
          containerPort: 8009

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-myapp
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: tomcat.lucky.com
    http:
      paths:
      - path: /
        pathType:  Prefix
        backend:
         service:
           name: tomcat
           port:
            number: 8080

 

我们看到 ingress的域名设置为   tomcat.lucky.com  。

本地host添加

192.168.157.199  tomcat.lucky.com

然后访问 http://tomcat.lucky.com/,通了,说明已经安装成功了。

k8s- nginx ingress 高可用部署(最新版,支持 k8s 1.22---1.19)第3篇  测试

 

 

 

教程中涉及到的文件可以下载:

 

链接:https://pan.baidu.com/s/1oRvhN2_nfVT2ndE2VEN2QQ
提取码:muxx 

 

上一篇:如何为Kafka集群选择合适的Topics/Partitions数量


下一篇:k8s中的nginx-ingress如何配置路径重定向