Lets assume we have simple Kubernetes service in Azure, which is sample webpage. It doesnt matter if it is type is NodePort or LoadBalancer or ClusterIp. And we want to connect it to our domain name, for example to alakbarv.com
Lets se (p.s if image is small, please zoom website ):
And it is our website:
First you should have Helm (The package manager for Kubernetes) installed. You may install this on below link proper to your OS, I installed it for Windows.
After that, create file named helm-rbac.yaml as below:
apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: tiller namespace: kube-system
And give command below for create service account and role binding:
kubectl apply -f helm-rbac.yaml
After Helm successfully installed and service account created you may install ingress with below command:
helm install stable/nginx-ingress --namespace kube-system --set controller.hostNetwork=true,controller.kind=DaemonSet
Then wait 20-30 seconds give command below to see your ingress controller and external IP of ingress. If External IP is in Pending status, just wait few seconds and give below command again to get your IP address of ingress:
kubectl get services --all-namespaces
As you see my External IP of Ingress controller is 188.8.131.52. This address will be need you later.
So, now you can go to Azure Portal and create a DNS Zone for your domain.
After adding DNS Zone, click to your Zone name on DNS Zones list, and then click Record Set.
If you want to redirect your main domain, example alakbarv.com to your service, then keep Name field empty, otherwise write your subdomain name for example myservice.alakbarv.com, in my own example I redirect it to main domain, so I keep it empty. Alias record set should be selected. On Azure resource section you should select Public IP address name which assigned to ingress controller, if you dont know its correct name, and you have more publicē ip addresses, you may find it easily. Give command:
kubectl get services --all-namespaces
Copy External IP of ingress controller (we already found it in above) and then give below command, just change ip address with your ingress ip address:
az network public-ip list --query "[?ipAddress=='184.108.40.206'].[name]"
It will return your resource name, so you may Select in in azure portal. Then click OK button in Azure portal.
Additionally, you should redirect your domain to the AZURE NS, for example, my alakbarv.com domain is in name.com. Firstly go to your domain panel, for example it is in name.com. In your case it can be different godaddy.com or other. Change NS to below NS:
get NS of Azure:
And then go to your domain panel (in my case it is name.com) update fileds like below:
Then in order to apply ingress rules create file ingress.yaml as below change domain name and service name to a service which you want to redirect:
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-world-ingress annotations: kubernetes.io/ingress.class: nginx certmanager.k8s.io/cluster-issuer: letsencrypt-staging nginx.ingress.kubernetes.io/rewrite-target: / namespace: default spec: tls: - hosts: - alakbarv.com rules: - host: alakbarv.com http: paths: - path: / backend: serviceName: trainingmanager-service servicePort: 80
And give below command to apply this script:
kubectl apply -f ingress.yaml
So, now check if it works!
P.S If it is first time you redirects your domain to Azure NS it can be take time.
And of course it will open with security warning due to it doesn’t have verified certificate you may install trusted certificated but it is different topic.