This pipeline will first build a Docker image of your app and push it to your Azure Container Registry. Then, it will deploy the image to your AKS cluster using a deployment and service.
The deployment.yaml file should define a deployment for your app. The following is an example:
To deploy multiple replicas of a Node.js frontend app with a MongoDB backend to an AKS cluster using a deployment YAML file, you can use the following code:
YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: 'nodejs:latest'
ports:
- containerPort: 3000
Use code with caution. Learn more
This deployment YAML file will create a deployment for your app with 3 replicas. The my-app container will be created and run with the image you specify. The container will be exposed on port 3000.
You can deploy this YAML file to your AKS cluster using the following command:
kubectl apply -f deployment.yaml
Once the deployment is created, you can access your app at the external IP address of your AKS cluster on port 3000.
To deploy multiple replicas of a MongoDB backend to an AKS cluster using a deployment YAML file, you can use the following code:
backenddeployment.yaml as mention in below
YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodbdeployment
spec:
replicas: 3
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo:latest
ports:
- containerPort: 27017
Use code with caution. Learn more
This deployment YAML file will create a deployment for your MongoDB backend with 3 replicas. The mongodb container will be created and run with the official MongoDB image. The container will be exposed on port 27017.
You can deploy this YAML file to your AKS cluster using the following command:
kubectl apply -f backenddeployment.yaml
Once the deployment is created, your MongoDB backend will be running and accessible on port 27017 within your AKS cluster.
You can then connect to your MongoDB backend from your Node.js frontend app using the following code:
JavaScript
const MongoClient = require('mongodb').MongoClient;
const client = new MongoClient('mongodb://mongodb:27017');
client.connect(function(err, db) {
if (err) {
console.log(err);
return;
}
// Do something with the database
});
Service.yml file
apiVersion: v1
kind: Service
metadata:
name: my-app
spec:
selector:
app: my-app
ports:
- protocol: TCP port: 80 targetPort: 3000
To create an Azure DevOps pipeline YAML file for deploying a Node.js frontend app with a MongoDB backend to an AKS cluster using a service and deployment, you can use the following code:
YAML
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
task: Docker@2
inputs:
containerRegistry: 'Azure Container Registry'
repository: 'my-app'
command: 'build'-
task: Kubernetes@1
inputs:
azureSubscription: 'my-subscription'
kubernetesServiceConnection: 'my-aks-cluster'
namespace: 'default'
command: 'deploy'
manifests:- frontdeployment.yaml
- service.yaml
To create an Azure DevOps pipeline YAML file for deploying a Node.js frontend app with a MongoDB backend to an AKS cluster using a service and deployment, you can use the following code:
YAML
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
task: Docker@2
inputs:
containerRegistry: 'Azure Container Registry'
repository: 'my-app'
command: 'build'-
task: Kubernetes@1
inputs:
azureSubscription: 'my-subscription'
kubernetesServiceConnection: 'my-aks-cluster'
namespace: 'default'
command: 'deploy'
manifests:- deployment.yaml
- backenddeployment.yaml
- service.yaml
Top comments (0)