Hi,
I have an Azure Kubernetes cluster (AKS) to which I wish to deploy from Octopus.
Currently, I’m having to add a copy of the config to the octopus server and reference it when using a version of kubectl.exe
(that matches the version of my AKS cluster), as shown here -
$clusterConfigPath = "#{KubernetesClusterConfigPath}"
$kubectlPath = "#{KubernetesKubectlPath}"
& $kubectlPath apply -f .\k8s\mapproxy-namespace.yaml --kubeconfig=$clusterConfigPath
To avoid the need to do this, I’d like to login using the az
CLI, and have that set the context. Unfortunately though, I’ve tried this in two different ways and both failed, as shown below.
Given that a Kubernetes cluster in AKS can be on one of several different versions, is there a reliable way to connect from Octopus without the need to store configs on the server, and maybe even avoid having to download multiple versions of kubectl.exe
?
Asuming the config would be set somewhere where kubectl.exe
would automatically find it
Trying to do it this way results in a Kubernetes error whereby there is not valid context.
The call to az aks get-credentials
works and and message is displayed saying that the current context has been successfully set in C:\Windows\system32\config\systemprofile.kube\config.
However, the fact no valid context error sugges that kubectl.exe
isn’t looking for the config in that location.
$kubectlPath = "#{KubernetesKubectlPath}"
az aks get-credentials --name #{AzureAksClusterName} --resource-group #{AzureResourceGroup}
& $kubectlPath apply -f .\k8s\mapproxy-namespace.yaml
Here is the relevant output of the above process step -
Merged "lmk-cs-kubernetes-non-live" as current context in C:\Windows\system32\config\systemprofile\.kube\config
error: unable to recognize ".\\k8s\\mapproxy-namespace.yaml": Get http://localhost:8080/api?timeout=32s: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.
Telling kubectl.exe
where to find the config after to call to az aks get-credentials
Because the successful call to az aks get-credentials
outputs the location of the config, I thought that I’d be able to pass that in to kubectl.exe
, but it fails saying that the config file cannot be found.
$kubectlPath = "#{KubernetesKubectlPath}"
az aks get-credentials --name #{AzureAksClusterName} --resource-group #{AzureResourceGroup}
& $kubectlPath apply -f .\k8s\mapproxy-namespace.yaml --kubeconfig=C:\Windows\system32\config\systemprofile\.kube\config
Here is the relevant output of the above process step -
Merged "lmk-cs-kubernetes-non-live" as current context in C:\Windows\system32\config\systemprofile\.kube\config
error: CreateFile C:\Windows\system32\config\systemprofile\.kube\config: The system cannot find the file specified.