Created
September 25, 2024 11:52
-
-
Save devops-school/d08e9875b51fd14a824ec2861660f584 to your computer and use it in GitHub Desktop.
Azure Pipeline to Deploy into AKS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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