.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.

Command prompt
cd myMicroservice

Create a deployment file

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

Run the following command to create an empty deploy-myMicroservice.yaml file.

Command prompt
echo . > deploy-myMicroservice.yaml

Open the deploy-myMicroservice.yaml file in the text editor of your choice and replace the contents with the following contents. Make sure to replace [YOUR DOCKER ID] with your actual Docker ID.

deploy-myMicroservice.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 based on the the settings in deploy-helloMicroservice.yaml:

Command prompt
kubectl apply -f deploy-myMicroservice.yaml

Test your deployed service

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

Command prompt
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