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
.
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.
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.
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.
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: /
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With