Posted on Leave a comment

Install Azure DevOps agent using powershell

With Azure devops you can create incredible automations. But in many cases you will need first to install the azure devops agent in order to run your tasks. Using the below powershell you can automate the installation of an azure devops agent.

New-Item "C:\agent" -itemType Directory
cd "C:\agent"
$url = "https://dev.azure.com/YOUR_ORG"
$token = "PAT_TOKEN"
$auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$token"))

$package = Invoke-RestMethod "$url/_apis/distributedtask/packages/agent?platform=win-x64&$`top=1" -Headers @{Authorization = "Basic $auth"}

$fileName = $package.value[0].fileName;
$downloadUrl = $package.value[0].downloadUrl;
    

Invoke-WebRequest -UseBasicParsing $downloadUrl -OutFile agent.zip
Expand-Archive -Force agent.zip -DestinationPath .
Remove-Item -Force agent.zip


.\config.cmd --unattended --replace --acceptTeeEula --work work --url https://dev.azure.com/YOUR_ORG --pool YOUR_POOL_NAME --auth path --token $token --runAsService --runAsAutoLogon --windowsLogonAccount USER --windowsLogonPassword USER_PASSWORD
.\run.cmd

During the installation you may notice a problem for the powershell task to write on the log file.

Nevertheless the agent will be installed successfully.

Posted on Leave a comment

kubectl commands cheat sheet for daily kubernetes administration

This is a cheat sheet for basic k8s commands that one k8s administrator can use daily.

Apply a YAML definition on k8s-cluster:

kubectl apply -f pod.yaml

Apply a definition on specific namespace:

Kubectl apply -f kati.yml -n namespacename

Create a new namespace:

kubectl create ns namespacename

Set k8s cluster context:

kubectl config use-context geralexgr-aks

Get k8s cluster context:

kubectl config view

Create a deployment:

kubectl create deployment new-app --image=hello-world:latest

Delete a deployment:

kubectl delete deployment nginx -n nginx

Describe a service:

Kubectl describe service/myservice

Get logs for pod:

Kubectl logs pod-123

Get cluster namespaces:

kubectl get namespace

Set active namespace:

kubectl config set-context --current --namespace nginx

Delete a pod:

kubectl delete pod nginx-pod

Scale a deployment:

kubectl scale --replicas=5 deployment/deploymentname

Get pods with labels:

kubectl get pods --show-labels

Get cluster scoped resources:

kubectl api-resources