Kubernetes ExternalName service types help us create a service in kubernetes mapping to an external hostname URL. In this document I will try to present a scenario for this purpose.
Scenario:
A common scenario is static files created from CMS/Backend systems which need to be hosted for you application. The ideal solution would be leveraging frontend application logic etc. to serve these files. But we will use kubernetes ExternalName service (as the title demands it).
Solution Design Diagram:
The image below shows the implementation approach for creating such solution.
Press enter or click to view image in full size

In this diagram, an Ingress controller (nginx-ingress) is configured to route traffic based on URL path. The default route always sends traffic to the application and only specific files are retrived from storage via ExternalName service.
Implementation Steps
prerequisites:
- kubectl
- helm : Not required if using manifests to install ingress controller
- Ingress controller (nginx-ingress): this can be installed using helm https://docs.nginx.com/nginx-ingress-controller/installation/installing-nic/installation-with-helm/ or manifest files: https://docs.nginx.com/nginx-ingress-controller/installation/installing-nic/installation-with-manifests/
Steps:
The following steps can be taken to achieve this:
- Create an externalname-service.yaml for our ExternalName service pointing to Azure Storage Account blob storage.
This will create an ExternalName service
apiVersion: v1
kind: Service
metadata:
name: storage-service
namespace: prod
spec:
type: ExternalName # Service type ExternalName
externalName: demostorage.blob.core.windows.net # replace with actual storage name
- Create a robots-ingress.yaml to create kubernetes ingress object to send traffic to this service based on file url.
This will create an ingress object with the rules
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: robots-ingress
annotations:
kubernetes.io/ingress.class: nginx # ingress class
nginx.ingress.kubernetes.io/backend-protocol: https #Backend Protocol
nginx.ingress.kubernetes.io/rewrite-target: /storage-container/robots.txt # storage account container name
spec:
rules:
- host: demohost.com.au # replace with actual hostname
http:
paths:- path: /robots.txt
pathType: Prefix
backend:
service:
name: storage-service
port:
number: 443
- path: /robots.txt
- run kubectl apply to create the resources
kubectl apply -f externalname-service.yaml
kubectl apply -f robots-ingress.yaml
Now if we visit the following url : demohost.com.au/robots.txt the contents of robots.txt file in azure storage container /storage-container/ in storage account demostorage.blob.core.windows.net will be displayed.
References :
Service
Expose an application running in your cluster behind a single outward-facing endpoint, even when the workload is split…
kubernetes.io
Custom annotations
This topic explains how you can use custom annotations with F5 NGINX Ingress Controller. Custom annotations enable you…
docs.nginx.com