Skip to content

Instantly share code, notes, and snippets.

@devops-school
Created September 25, 2024 11:52
Show Gist options
  • Select an option

  • Save devops-school/d08e9875b51fd14a824ec2861660f584 to your computer and use it in GitHub Desktop.

Select an option

Save devops-school/d08e9875b51fd14a824ec2861660f584 to your computer and use it in GitHub Desktop.
Azure Pipeline to Deploy into AKS
trigger:
- master
pool:
DevOpsSchool
variables:
imageName: 'nginx:latest'
aksResourceGroup: 'aks'
aksClusterName: 'CSCluster'
namespace: 'default'
stages:
- stage: Deploy
displayName: Deploy to AKS
jobs:
- job: DeployToAKS
displayName: Deploy to AKS
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'aks' # Replace with your Azure service connection
scriptType: 'bash'
scriptLocation: 'inlineScript' # Fixed typo here
inlineScript: |
echo "Logging in to AKS cluster"
az aks get-credentials --resource-group $(aksResourceGroup) --name $(aksClusterName) --overwrite-existing
echo "Creating a Kubernetes deployment for NGINX"
kubectl create namespace $(namespace) --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: $(namespace)
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: $(imageName)
ports:
- containerPort: 80
EOF
echo "Exposing NGINX service"
kubectl expose deployment nginx-deployment --type=LoadBalancer --name=nginx-service --namespace=$(namespace) --port=80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment