https://github.com/trstringer/az-aks-ssh
SSH into Azure Kubernetes Service (AKS) nodes
https://github.com/trstringer/az-aks-ssh
aks-cluster azure azure-kubernetes-service kubernetes ssh
Last synced: 9 months ago
JSON representation
SSH into Azure Kubernetes Service (AKS) nodes
- Host: GitHub
- URL: https://github.com/trstringer/az-aks-ssh
- Owner: trstringer
- License: mit
- Created: 2021-04-18T19:26:29.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-13T14:20:32.000Z (about 3 years ago)
- Last Synced: 2024-10-04T13:26:25.935Z (over 1 year ago)
- Topics: aks-cluster, azure, azure-kubernetes-service, kubernetes, ssh
- Language: Shell
- Homepage:
- Size: 53.7 KB
- Stars: 22
- Watchers: 2
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SSH into AKS agent nodes
There is documentation on [how to SSH into AKS nodes (Microsoft docs)](https://docs.microsoft.com/en-us/azure/aks/ssh). That process is long and quite manual. This script automates this.
*Note: this script is currently in alpha and should not be used in a production environment.*
## Setup and dependencies
Clone this git repo and use the `az-aks-ssh.sh` direction (see below for usage).
Dependencies:
* kubectl
* Azure CLI
## Usage
```
Usage:
SSH into an AKS agent node (pass in -c to run a single command
or omit for an interactive session):
./az-aks-ssh.sh \
-g|--resource-group \
-n|--cluster-name \
-d|--node-name \
[-c|--command ] \
[-o|--output-file ]
Delete all locally generated SSH keys (~/.ssh/az_aks_*):
./az-aks-ssh.sh --clear-local-ssh-keys
Delete the SSH proxy pod:
./az-aks-ssh.sh --delete-ssh-pod
Cleanup SSH (delete SSH proxy pod and remove all keys):
./az-aks-ssh.sh --cleanup
```
## Examples
**SSH into any agent node in an interactive SSH session**
```
$ ./az-aks-ssh.sh -g rg1 -n aks1 -d any
```
**SSH into a specific agent node (get node name from `kubectl get no`)**
```
$ ./az-aks-ssh.sh -g rg1 -n aks1 -d cluster_node
```
**Run a single command non-interactively**
```
$ ./az-aks-ssh.sh -g rg1 -n aks1 -d any -c "ps -aux"
```
**Run a command non-interactively and save the output to a file**
```
$ ./az-aks-ssh.sh -g rg1 -n aks1 -d any -c "ps -aux" -o ~/aks-ssh.out
```
**Cleanup the environment (delete agent node SSH keys locally and remove the SSH proxy pod)**
```
$ ./az-aks-ssh.sh --cleanup
```
## More information
**Design**

**SSH keys**
The SSH keys are generated for individual nodes. This ensures that keys are not being reused for multiple hosts. `--cleanup` removes all keys that match the prefix: `~/.ssh/az_aks*`.
**SSH proxy pod**
This design uses a proxy pod that sleeps forever so that it can be reused. `--cleanup` deletes this pod from the Kubernetes cluster. To see this pod you can run `kubectl get po aks-ssh-session`.