简体   繁体   中英

Kubernetes expose multiple pods

I have a kubernetes cluster with multiple pods from different images.

I want to be able to expose each of those pods so I will be able to access them using an external DNS record (outside the cluster).

For example: Let's say I have 3 pods (pod1,pod2,pod3), I want to be able to access them from outside the cluster this way:

http://pod1.mydomain.com

http://pod2.mydomain.com

http://pod3.mydomain.com

Is there a way to do it?

Thanks

In AWS you can easily expose PODs using ELB - Kubernetes can automatically create proper ELBs for you. It means that Kubernetes spawn ELB and then attach it to proper services using nodes ports. When you have ELBs in place you can use external-dns plugin metioned by GarMan which can attach DNS records to those ELBs using AWS Route53 integration. So you need to:

  1. Add proper rights to Kubernetes so he can create ELBs and DNS record in Route53 (part of Kubernetes installation and external-dns plugin installation)
  2. Attach proper service to your pod

Example service would look like:

apiVersion: v1
kind: Service
metadata:
  name: public-pod1
  namespace: your-deployment
  labels:
    app: pod1
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
    service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
    external-dns.alpha.kubernetes.io/hostname: pod1.mydomain.com.
spec:
  type: LoadBalancer
  loadBalancerSourceRanges:
  - 0.0.0.0/0 # Ingress SG for your ELB
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80 #That should match your app's port
  selector:
    app: pod1

外部dns( https://github.com/kubernetes-incubator/external-dns )就是为了做到这一点,您用您要为其提供的dns名称来注释您的服务,而external-dns为此创建了相关的dns条目。您。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM