Adding a Nutanix Karbon Kubernetes Target

We are using Nutanix’s Karbon solution to create our on-premises Kubernetes Cluster. Part of the Karbon solution is that it manages the cluster login security.

To run kubectl I login to a Nutanix CLI tool (called Karbonctl). It then passes back a kubeconfig file with a token that is valid for 24 hours.

Does Octopus have a way for me to integrate this process this so I can use a Kubernetes Cluster Target?

Greetings @OctopusSchaff, thanks for reaching out! We’ve not used Karbon before, however, we have successfully integrated with Rancher and RedHat OpenShift so I’m thinking this will be possible with a bit of work.

Our runbooks feature has the ability to schedule triggers. You can configure the runbook to run on a worker that has the Nutanix CLI installed. The worker can run the CLI and capture the token that is passed back then use the Octpus API to update the token value similar to this

# Define working variables
$octopusUrl = $OctopusParameters['Global.Base.Url']
$octopusApiKey = $OctopusParameters['Global.Octopus.Api.Key']
$headers = @{ "X-Octopus-ApiKey" = $octopusApiKey }
$spaceId = $OctopusParameters['Octopus.Space.Id']

# Get token value
#$token = $OctopusParameters["Octopus.Action[Get token].Output.RancherLoginToken"]
$token = $OctopusParameters["Octopus.Action[Save token to Rancher account].Output.RancherLoginToken"]

# Get account
Write-Host "Getting account named 'Rancher' ..."
$account = (Invoke-RestMethod -Method Get -Uri "$octopusUrl/api/$spaceId/accounts" -Headers $headers).Items | Where-Object {$_.Name -eq "Rancher"}

# Check to see if account exists
if ($null -eq $account)
  # Create JSON payload
  Write-Host "Account 'Rancher' not found, creating new one ..."
$jsonPayload = @"
  "AccountType": "Token",
  "Token": {
  "HasValue": true,
  "NewValue": "$token"
  "Name": "Rancher",
  "Description": "",
  "TenantedDeploymentParticipation": "Untenanted",
  "TenantTags": [],
  "TenantIds": [],
  "EnvironmentIds": []

  # Create new token
  Invoke-RestMethod -Method Post -Uri "$octopusUrl/api/$spaceId/accounts" -Body $jsonPayload -Headers $headers
    # Update account token value
    Write-Host "Found account 'Rancher', updating token value ..."
 	$account.Token.NewValue = $token
    # Post to server
    Invoke-RestMethod -Method Put -Uri "$octopusUrl/api/$spaceId/accounts/$($account.Id)" -Body ($account | ConvertTo-Json -Depth 10) -Headers $headers

Hope this helps!



1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.