Kubernetes Services task failing in VSTS.
Fix for this issue has been deployed. Now you can pin your kubernetes task to a particular version of kubectl client by specifying the version in the Advance section of the task.
If your kubernetes task is failing since 17/12/2017, this is because latest version 1.9.0 of kubectl is released. Unfortunately, kubernetes task always pulls the latest version of kubectl which is not compatible with the older kubectl server.
The workaround involves having kubectl setup on the agent machine so that task does not pull the latest version.
If you are running release on your private agent.
Download the version of kubectl you want from https://storage.googleapis.com/kubernetes-release/release/%version%/bin/windows/amd64/kubectl.exe like https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/windows/amd64/kubectl.exe
Keep it in a folder say "C:\kube\".
Now update the Path variable to include the folder path.
Once u have made the change make sure to restart the agent and if running agent as service restart the service. Check by echoing Path variable if the change is reflecting or not. You might have to also restart your command prompt.
If you are running release on hosted agent
Download the desired kubectl version.
Check it in the source code or add it as a part of artifact.
In the release definition add a powershell task and set Type to file path.
Use file picker in Script path to navigate to kubectl.exe
Select till folder path of kubectl.exe in above example "$(System.DefaultWorkingDirectory)/first/"
Switch the type to Inline script.
In inline script add
Write-Host "##vso[task.setvariable variable=path;]$env:path;$Args"
In Argument section add the folder path of kubectl.
This will fix the release add the k8 task will start using the k8 client which is part of the artifact.
If you face any issue, you can add command line task to echo Path variable to check if it is updated or not. You can also execute where kubectl to check which kubectl is being used.