.NET Tutorial - Deploy a microservice to Azure

Deploy to Azure

Return to app directory

Since you opened a new command prompt in the previous step, you'll need to return to the directory you created your service in.

Since you opened a new terminal in the previous step, you'll need to return to the directory you created your service in.

Terminal
cd MyMicroservice

Create a deployment file

The AKS tools use a .yaml file to define how to deploy your container.

Create a file called deploy.yaml with this command:

Terminal
touch deploy.yaml
Terminal
fsutil file createnew deploy.yaml 0

You can then open it in your favorite text editor.

You can then open it in your favorite text editor manually or with this command:

Terminal
open deploy.yaml
Terminal
start deploy.yaml

Replace the content of the deploy.yaml to the following in the text editor, making sure to replace [YOUR DOCKER ID] with your actual Docker ID.

deploy.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mymicroservice
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mymicroservice
    spec:
      containers:
      - name: mymicroservice
        image: [YOUR DOCKER ID]/mymicroservice:latest
        ports:
        - containerPort: 80
        env:
        - name: ASPNETCORE_URLS
          value: http://*:80
  selector:
    matchLabels:
      app: mymicroservice
---
apiVersion: v1
kind: Service
metadata:
  name: mymicroservice
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: mymicroservice

Run deployment

Run the following command to deploy your microservice based on the settings in deploy.yaml:

Terminal
kubectl apply -f deploy.yaml

Test your deployed service

Run the following command to see the details of your deployed service:

Terminal
kubectl get service mymicroservice --watch

Among other things, the previous command will show the external IP address that your service is available on (EXTERNAL-IP).

Using the external IP address, open a new browser window and navigate to http://[YOUR EXTERNAL IP ADDRESS]/weatherforecast

If the EXTERNAL-IP is marked as <pending>, a new line will automatically appear once the external IP has been allocated.

Press CTRL+C on your command prompt to end the kubectl get service command.

Press CTRL+C on your terminal to end the kubectl get service command

Congratulations! You've deployed a microservice to Azure.

Continue