# Cheat Sheet

## Get cluster kubeconfig credentials

{% hint style="info" %}
Backup your current kubeconfig.
{% endhint %}

```
az account set --subscription "MY-SUBSCRIPTION"
az aks get-credentials --resource-group MY-RG --name MY-CLUSTER
```

## Load Balancer

<https://docs.microsoft.com/pt-br/azure/aks/internal-lb>

## Log Analytics

To enable AKS to store your pod logs, go to your AKS resource, Monitoring section, Logs. Create a workspace and enable logs.

To enable kube-apiserver logs go to your AKS Resource Group (the RG you created do deploy AKS service, not the RG that is automatically generated by AKS), Monitoring section, Diagnostic settings, click on your AKS from the list, on "Diagnostics settings" screen, click on "Add diagnostic setting".

Input a name, check "Send to Log Analytics", select you subscription and workspace, check the logs you want and click on save.

Wait a few minutes, then you query `AzureDiagnostics` logs:

```
AzureDiagnostics
| where Category == "kube-apiserver"
| project log_s
```

### References

<https://docs.microsoft.com/en-us/azure/aks/view-master-logs>

## SSH to nodes

Set your subscription.

```bash
az account set --subscription "MY-SUBSCRIPTION"
```

Set an env var with your cluster resources RG.

```bash
CLUSTER_RESOURCE_GROUP=MC_my-aks-name
```

Add your RSA key to the node.

```bash
az vm user update \
    --resource-group $CLUSTER_RESOURCE_GROUP \
    --name PUT-YOUR-NODE-NAME-HERE \
    --username azureuser \
    --ssh-key-value ~/.ssh/id_rsa.pub
```

Get your node IP.

```bash
az vm list-ip-addresses --resource-group $CLUSTER_RESOURCE_GROUP -o table
```

Run a pod.

```bash
kubectl run -it --rm aks-ssh --image=debian
```

Install SSH client.

```bash
apt-get update && apt-get install openssh-client vim -y
```

Setup the id\_rsa file.

```bash
mkdir ~/.ssh
vi ~/.ssh/id_rsa
# Paste your id_rsa
chmod 600 ~/.ssh/id_rsa
```

SSH to your node.

```bash
ssh azureuser@PUT.YOUR.NODE.IP.HERE
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.devops.buzz/public/aks/cheat-sheet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
