Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Ingress to External Service?

Tags:

Say I have a service that isn't hosted on Kubernetes. I also have an ingress controller and cert-manager set up on my kubernetes cluster.

Because it's so much simpler and easy to use kubernetes ingress to control access to services, I wanted to have a kubernetes ingress that points to a non-kubernetes service.

For example, I have a service that's hosted at https://10.0.40.1:5678 (ssl required, but self signed certificate) and want to access at service.example.com.

like image 601
cclloyd Avatar asked Sep 03 '19 02:09

cclloyd


People also ask

What is external name service in Kubernetes?

An ExternalName service is a special case of service that does not have selectors. It does not define any ports or endpoints. Rather, it serves as a way to return an alias to an external service residing outside the cluster.

What is difference between ingress and service in Kubernetes?

Unlike NodePort or LoadBalancer, Ingress is not actually a type of service. Instead, it is an entry point that sits in front of multiple services in the cluster. It can be defined as a collection of routing rules that govern how external users access services running inside a Kubernetes cluster.

Which ingress is used to route traffic from single IP to multiple services?

Kubernetes ingress resources are used to configure the ingress rules and routes for individual Kubernetes services. Using an ingress controller and ingress rules, a single IP address can be used to route traffic to multiple services in a Kubernetes cluster.


2 Answers

You can do it by manual creation of Service and Endpoint objects for your external server.

Objects will looks like that:

apiVersion: v1 kind: Service metadata:   name: external-ip spec:   ports:   - name: app     port: 80     protocol: TCP     targetPort: 5678   clusterIP: None   type: ClusterIP --- apiVersion: v1 kind: Endpoints metadata:   name: external-ip subsets: - addresses:   - ip: 10.0.40.1   ports:   - name: app     port: 5678     protocol: TCP 

Then, you can create an Ingress object which will point to Service external-ip with port 80:

apiVersion: extensions/v1beta1 kind: Ingress metadata:   name: external-service spec:   rules:   - host: service.example.com     http:       paths:       - backend:           serviceName: external-ip           servicePort: 80         path: / 
like image 142
Anton Kostenko Avatar answered Oct 04 '22 04:10

Anton Kostenko


If your external service has a dns entry configured on it, you can use kubernetes externalName service.

--- apiVersion: v1 kind: Service metadata:   name: my-service   namespace: prod spec:   type: ExternalName   externalName: myexternal.http.service.com --- apiVersion: extensions/v1beta1 kind: Ingress metadata:   name: externalNameservice   namespace: prod spec:   rules:   - host: service.example.com     http:       paths:       - backend:           serviceName: my-service           servicePort: 80         path: / 

In this way, kubernetes create cname record my-service pointing to myexternal.http.service.com

like image 25
c4f4t0r Avatar answered Oct 04 '22 05:10

c4f4t0r