Exercise - Enable Network Access To An Application - Training - Microsoft Learn
Exercise - Enable Network Access To An Application - Training - Microsoft Learn
" 100 XP
You successfully deployed the video rendering service website to your cluster. But you noticed
that you couldn't access the website from any client external to the cluster. The problem is that
you haven't exposed your application to the internet yet. By default, Kubernetes blocks all
external traffic. You'll need to add an ingress rule to allow traffic into the cluster.
) Important
You need your own Azure subscription to run this exercise, and you might incur charges. If
you don't already have an Azure subscription, create a free account before you begin.
2. In Cloud Shell, create a manifest file for the Kubernetes service called service.yaml .
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 1/8
28/10/22, 10:32 Exercise - Enable network access to an application - Training | Microsoft Learn
Bash
touch service.yaml
4. Open the service.yaml file, and add the following code section of YAML.
YAML
#service.yaml
apiVersion: v1
kind: Service
metadata:
name: contoso-website
In this code, you added the first two keys to tell Kubernetes the apiVersion and kind of
manifest you're creating. The name is the name of the service. You'll use it to identify and
query the service information when you use kubectl .
5. You define how the service will behave in the specification section of the manifest file. The
first behavior you need to add is the type of service. Set the type key to clusterIP .
YAML
#service.yaml
apiVersion: v1
kind: Service
metadata:
name: contoso-website
spec:
type: ClusterIP
6. You define the pods the service will group and provide coverage by adding a selector
section to the manifest file. Add the selector , and set the app key value to the contoso-
website label of your pods as specified in your earlier deployment's manifest file.
YAML
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 2/8
28/10/22, 10:32 Exercise - Enable network access to an application - Training | Microsoft Learn
#service.yaml
apiVersion: v1
kind: Service
metadata:
name: contoso-website
spec:
type: ClusterIP
selector:
app: contoso-website
7. You define the port-forwarding rules by adding a ports section to the manifest file. The
service must accept all TCP requests on port 80 and forward the request to the HTTP target
port for all pods matching the selector value defined earlier.
YAML
#service.yaml
apiVersion: v1
kind: Service
metadata:
name: contoso-website
spec:
type: ClusterIP
selector:
app: contoso-website
ports:
8. Save the manifest file by pressing Ctrl-S , and close the editor by pressing Ctrl-Q .
Bash
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 3/8
28/10/22, 10:32 Exercise - Enable network access to an application - Training | Microsoft Learn
kubectl apply f ./service.yaml
Output
service/contoso-website created
2. Run the kubectl get service command to check if the deployment was successful.
Bash
The command should output a result similar to the following example. Make sure the
column CLUSTER-IP is filled with an IP address and the column EXTERNAL-IP is <none> . Also,
make sure the column PORT(S) is defined to 80/TCP .
Output
With the external IP set to <none> , the application isn't available to external clients. The
service is only accessible to the internal cluster.
1. In Cloud Shell, create a manifest file for the Kubernetes service called ingress.yaml .
Bash
touch ingress.yaml
3. Open the ingress.yaml file, and add the following code section of YAML.
YAML
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 4/8
28/10/22, 10:32 Exercise - Enable network access to an application - Training | Microsoft Learn
#ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: contoso-website
In this code, you added the first two keys to tell Kubernetes the apiVersion and kind of
manifest you're creating. The name is the name of the ingress. You'll use it to identify and
query the ingress information when you use kubectl .
4. Create an annotations key inside the metadata section of the manifest file called to use the
HTTP application routing add-on for this ingress. Set the key to
kubernetes.io/ingress.class and a value of addon-http-application-routing .
YAML
#ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: contoso-website
annotations:
kubernetes.io/ingress.class: addon-http-application-routing
5. Set the fully qualified domain name (FQDN) of the host allowed access to the cluster.
In Cloud Shell, run the az network dns zone list command to query the Azure DNS zone
list.
Bash
az aks show \
-g $RESOURCE_GROUP \
-n $CLUSTER_NAME \
-o tsv \
--query
addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName
6. Copy the output, and update the ingress.yaml file to match the following YAML. Replace
the <zone-name> placeholder value with the ZoneName value you copied.
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 5/8
28/10/22, 10:32 Exercise - Enable network access to an application - Training | Microsoft Learn
YAML
#ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: contoso-website
annotations:
kubernetes.io/ingress.class: addon-http-application-routing
spec:
rules:
7. Next up, add the back-end configuration to your ingress rule. Create a key named http and
allow the http protocol to pass through. Then, define the paths key that will allow you to
filter whether this rule applies to all paths of the website or only some of them.
YAML
#ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: contoso-website
annotations:
kubernetes.io/ingress.class: addon-http-application-routing
spec:
rules:
- host: contoso.<uuid>.<region>.aksapp.io
http:
paths:
service:
port:
8. Save the manifest file by pressing Ctrl-S , and close the editor by pressing Ctrl-Q .
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 6/8
28/10/22, 10:32 Exercise - Enable network access to an application - Training | Microsoft Learn
1. In Cloud Shell, run the kubectl apply command to submit the ingress manifest to your
cluster.
Bash
Output
ingress.extensions/contoso-website created
2. Run the kubectl get ingress command to check if the deployment was successful.
Bash
Output
Make sure the ADDRESS column of the output is filled with an IP address. That's the address
of your cluster.
7 Note
There can be a delay between the creation of the ingress and the creation of the zone
record. It can take up to five minutes for zone records to propagate.
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 7/8
28/10/22, 10:32
p p p g
Exercise - Enable network access to an application - Training | Microsoft Learn
3. Open your browser, and go to the FQDN described in the output. You should see a website
that looks like the following example screenshot.
Continue T
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/7-exercise-expose-app 8/8