Skip to content

Commit

Permalink
Update kubelogin path and add instructions in README
Browse files Browse the repository at this point in the history
  • Loading branch information
tg123 committed Feb 16, 2024
1 parent 8e74dee commit a0b6b95
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/aks-kubelogin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

var server = "https://example.hcp.eastus.azmk8s.io"; // the server url of your aks
var clientid = "00000000-0000-0000-0000-000000000000"; // the client id of the your msi
var kubeconfig = @"C:\bin\kubelogin.exe"; // the path to the kubelogin.exe
var kubelogin = @"C:\bin\kubelogin.exe"; // the path to the kubelogin.exe

using var configstream = new MemoryStream(Encoding.ASCII.GetBytes($"""
apiVersion: v1
Expand Down Expand Up @@ -34,7 +34,7 @@
- 6dae42f8-4368-4678-94ff-3960e28e3630
- --client-id
- {clientid}
command: {kubeconfig}
command: {kubelogin}
env: null
"""));

Expand Down
24 changes: 24 additions & 0 deletions examples/aks-kubelogin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# AKS C# example using kubelogin + MSI

This example shows how to use the [kubelogin](https://github.com/Azure/kubelogin) to authenticate using [managed identities](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview) with Azure Kubernetes Service (AKS) using the C# SDK.


## Prerequisites

- turn on AAD support for AKS, see [here](https://docs.microsoft.com/en-us/azure/aks/managed-aad)
- create a managed identity for the AKS cluster
- assign the managed identity the `Azure Kubernetes Service RBAC Cluster Admin` (or other RBAC permission) on the AKS cluster
- assign the managed identity to the VM, see [here](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm)
- install the [kubelogin](https://github.com/Azure/kubelogin) to your machine

## Running the code

*You must the the code on VM with MSI*

- Replace `server` with the address of your AKS cluster
- Replace `clientid` with the client id of the managed identity
- Replace `kubelogin` with the path to the kubelogin executable

```
dotnet run
```

0 comments on commit a0b6b95

Please sign in to comment.