ZhangZhihui's Blog  

If we only have one service, we can easily add an A record in the domain in AWS Route 53. 

But it will be a pain when we have a lot more of them, because we would have to create a lot of A records to route traffix to each of the services. 

A better solution in this case will be to use Ingress, which will allow us setup A record only once but can define multiple rules in the configuration file to route traffic to different services.

 

 

 

 

 

To use Ingress, first change the service type from LoadBalancer to ClusterIP, or delete the type:

复制代码
apiVersion: v1
kind: Service
metadata:
  name: zimple-bank-api-service
spec:
  selector:
    app: zimple-bank-api
  ports:
    - protocol: TCP
      port: 80 # on which the server will listen to incoming request
      targetPort: 8080 # port of the container where the request will be sent to
  type: ClusterIP
复制代码

Next, install the Ingress controller: https://kubernetes.github.io/ingress-nginx/deploy/#aws

Next, create ingress.yaml and apply it:

复制代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: zimple-bank-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: "api.zimple-bank.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: zimple-bank-api-service
            port:
              number: 80
复制代码

Next, copy the address and paste it in the A record for the host domain:

Finally, add IngressClass in the ingress.yaml:

复制代码
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  name: nginx
spec:
  controller: k8s.io/ingress-nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: zimple-bank-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: "api.zimple-bank.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: zimple-bank-api-service
            port:
              number: 80
复制代码

 

posted on   ZhangZhihuiAAA  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示