2023-04-26 12:30:11 +03:00
|
|
|
# Azure Kubernetes Service (AKS) kubectl plugin
|
2021-11-19 20:51:00 +03:00
|
|
|
|
2023-04-26 12:07:56 +03:00
|
|
|
`kubectl-aks` is a `kubectl` plugin that provides a set of commands that enable
|
|
|
|
users to interact with an AKS cluster even when the control plane is not
|
|
|
|
functioning as expected. For example, users can still use the plugin to debug
|
|
|
|
their cluster if the API server is not working correctly. This plugin allows
|
|
|
|
users to perform various tasks, retrieve information, and execute commands
|
|
|
|
against the cluster nodes, regardless of the control plane's state.
|
2023-04-05 19:53:54 +03:00
|
|
|
|
2023-04-26 12:07:56 +03:00
|
|
|
It's important to note that this plugin does not replace the Azure CLI,
|
|
|
|
[az](https://learn.microsoft.com/en-us/cli/azure/?view=azure-cli-latest).
|
|
|
|
Instead, it complements it by offering additional commands and providing users
|
|
|
|
with a kubectl-like experience. In practice, users will use az to create and
|
|
|
|
delete their AKS cluster, and then use kubectl and kubectl-aks to interact with
|
|
|
|
and debug it.
|
2021-11-19 20:51:00 +03:00
|
|
|
|
2022-01-18 18:51:53 +03:00
|
|
|
Going through the following documentation will help you to understand each
|
|
|
|
available command and which one is the most suitable for your case:
|
2021-11-19 20:51:00 +03:00
|
|
|
|
2022-01-18 18:51:53 +03:00
|
|
|
- [run-command](docs/run-command.md)
|
|
|
|
- [check-apiserver-connectivity](docs/check-apiserver-connectivity.md)
|
2023-03-02 14:46:41 +03:00
|
|
|
- [config](docs/config.md)
|
2022-01-18 18:51:53 +03:00
|
|
|
|
2023-04-20 12:16:57 +03:00
|
|
|
Consider `kubectl-aks` expects the cluster to use virtual machine scale sets,
|
2023-04-05 19:53:54 +03:00
|
|
|
which is the case of an AKS cluster. And, the use of the `--node` flag requires
|
|
|
|
the Kubernetes control plane to up and running, because the VMSS instance
|
|
|
|
information of the node will be retrieved from the Kubernetes API server.
|
2022-01-18 18:51:53 +03:00
|
|
|
|
2023-04-05 19:53:54 +03:00
|
|
|
However, in case of issues with the Kubernetes control plane, you can reuse the
|
|
|
|
already stored VMSS instance information, see [config](docs/config.md) command.
|
|
|
|
Or, if it is a cluster you have never used before on that host, you can retrieve
|
|
|
|
such information from the [Azure portal](https://portal.azure.com/) and pass it
|
|
|
|
to the commands using the `--id` flag or separately with the `--subscription`,
|
|
|
|
`--node-resource-group`, `--vmss` and `--instance-id` flags.
|
2022-01-18 18:51:53 +03:00
|
|
|
|
|
|
|
## Install
|
|
|
|
|
2023-04-20 12:16:57 +03:00
|
|
|
There is multiple ways to install the `kubectl-aks`.
|
2023-04-05 19:53:54 +03:00
|
|
|
|
2023-04-05 20:03:53 +03:00
|
|
|
### Using krew
|
|
|
|
|
|
|
|
[krew](https://sigs.k8s.io/krew) is the recommended way to install `kubectl-aks`.
|
|
|
|
You can follow the [krew's
|
|
|
|
quickstart](https://krew.sigs.k8s.io/docs/user-guide/quickstart/) to install it
|
|
|
|
and then install `kubectl-aks` by executing the following command:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
kubectl krew install aks
|
|
|
|
kubectl aks version
|
|
|
|
```
|
|
|
|
|
2023-04-05 19:53:54 +03:00
|
|
|
### Install a specific release
|
|
|
|
|
|
|
|
It is possible to download the asset for a given release and platform from the
|
2023-04-20 12:16:57 +03:00
|
|
|
[releases page](https://github.com/azure/kubectl-aks/releases/), uncompress and
|
|
|
|
move the `kubectl-aks` executable to any folder in your `$PATH`.
|
2023-04-05 19:53:54 +03:00
|
|
|
|
2022-01-18 18:51:53 +03:00
|
|
|
```bash
|
2023-04-05 20:03:53 +03:00
|
|
|
VERSION=v0.2.0
|
2023-04-20 12:16:57 +03:00
|
|
|
curl -sL https://github.com/azure/kubectl-aks/releases/latest/download/kubectl-aks-linux-amd64-${VERSION}.tar.gz | sudo tar -C /usr/local/bin -xzf - kubectl-aks
|
|
|
|
kubectl aks version
|
2022-01-18 18:51:53 +03:00
|
|
|
```
|
|
|
|
|
2023-04-05 19:53:54 +03:00
|
|
|
### Compile from source
|
|
|
|
|
2023-04-20 12:16:57 +03:00
|
|
|
To build `kubectl-aks` from source, you'll need to have a Golang version 1.17
|
2023-04-05 19:53:54 +03:00
|
|
|
or higher installed:
|
|
|
|
|
|
|
|
```bash
|
2023-04-20 12:16:57 +03:00
|
|
|
git clone https://github.com/Azure/kubectl-aks.git
|
|
|
|
cd kubectl-aks
|
2023-04-05 19:53:54 +03:00
|
|
|
# Build and copy the resulting binary in $HOME/.local/bin/
|
|
|
|
make install
|
2023-04-20 12:16:57 +03:00
|
|
|
kubectl aks version
|
2023-04-05 19:53:54 +03:00
|
|
|
```
|
2022-01-18 18:51:53 +03:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```bash
|
2023-04-20 12:16:57 +03:00
|
|
|
$ kubectl aks --help
|
2023-04-26 12:30:11 +03:00
|
|
|
Azure Kubernetes Service (AKS) kubectl plugin
|
2022-01-18 18:51:53 +03:00
|
|
|
|
|
|
|
Usage:
|
2023-04-20 12:16:57 +03:00
|
|
|
kubectl-aks [command]
|
2022-01-18 18:51:53 +03:00
|
|
|
|
|
|
|
Available Commands:
|
2023-03-02 14:46:41 +03:00
|
|
|
check-apiserver-connectivity Check connectivity between the nodes and the Kubernetes API Server
|
|
|
|
completion Generate the autocompletion script for the specified shell
|
|
|
|
config Manage configuration
|
|
|
|
help Help about any command
|
|
|
|
run-command Run a command in a node
|
|
|
|
version Show version
|
2022-01-18 18:51:53 +03:00
|
|
|
|
|
|
|
Flags:
|
2023-04-20 12:16:57 +03:00
|
|
|
-h, --help help for kubectl-aks
|
2022-01-18 18:51:53 +03:00
|
|
|
|
2023-04-20 12:16:57 +03:00
|
|
|
Use "kubectl-aks [command] --help" for more information about a command.
|
2022-01-18 18:51:53 +03:00
|
|
|
```
|
|
|
|
|
2023-04-20 12:16:57 +03:00
|
|
|
It is necessary to sign in to Azure to run any `kubectl-aks` command. To do so,
|
2022-01-18 18:51:53 +03:00
|
|
|
you can use any authentication method provided by the [Azure
|
|
|
|
CLI](https://github.com/Azure/azure-cli/) using the `az login` command; see
|
|
|
|
further details
|
|
|
|
[here](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli).
|
|
|
|
However, if you do not have the Azure CLI or have not signed in yet,
|
2023-04-20 12:16:57 +03:00
|
|
|
`kubectl-aks` will open the default browser and load the Azure sign-in page where
|
2022-01-18 18:51:53 +03:00
|
|
|
you need to authenticate.
|
|
|
|
|
2023-07-10 17:01:09 +03:00
|
|
|
### Permissions
|
|
|
|
|
|
|
|
In order to run `kubectl-aks` commands, the user/service principal must have the permissions to perform the
|
|
|
|
following [operations](https://learn.microsoft.com/en-us/azure/role-based-access-control/resource-provider-operations):
|
|
|
|
|
|
|
|
- Run command on the instances: `Microsoft.Compute/virtualMachineScaleSets/virtualmachines/runCommand/action`
|
|
|
|
- List Virtual Machine Scale Sets (VMSS): `Microsoft.Compute/virtualMachineScaleSets/virtualMachines/read`
|
|
|
|
- List Virtual Machine Scale Set Instances (VMSS Instances): `Microsoft.Compute/virtualMachineScaleSets/read`
|
|
|
|
|
|
|
|
Normally if you are using [built-in](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles)
|
|
|
|
roles e.g Contributor, you should have the above permissions. However, if you are
|
|
|
|
using [custom roles](https://learn.microsoft.com/en-us/azure/role-based-access-control/custom-roles-portal) for a
|
|
|
|
service principal, you need to make sure that the permissions are granted.
|
|
|
|
|
2021-11-19 20:51:00 +03:00
|
|
|
## Contributing
|
|
|
|
|
2023-07-10 17:01:09 +03:00
|
|
|
This project welcomes contributions and suggestions. Most contributions require
|
2022-01-18 18:51:53 +03:00
|
|
|
you to agree to a Contributor License Agreement (CLA) declaring that you have
|
|
|
|
the right to, and actually do, grant us the rights to use your contribution. For
|
|
|
|
details, visit https://cla.opensource.microsoft.com.
|
2021-11-19 20:51:00 +03:00
|
|
|
|
2022-01-18 18:51:53 +03:00
|
|
|
When you submit a pull request, a CLA bot will automatically determine whether
|
|
|
|
you need to provide a CLA and decorate the PR appropriately (e.g., status check,
|
|
|
|
comment). Simply follow the instructions provided by the bot. You will only need
|
|
|
|
to do this once across all repos using our CLA.
|
2021-11-19 20:51:00 +03:00
|
|
|
|
2022-01-18 18:51:53 +03:00
|
|
|
This project has adopted the [Microsoft Open Source Code of
|
|
|
|
Conduct](https://opensource.microsoft.com/codeofconduct/). For more information
|
|
|
|
see the [Code of Conduct
|
|
|
|
FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact
|
|
|
|
[opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional
|
|
|
|
questions or comments.
|
2021-11-19 20:51:00 +03:00
|
|
|
|
|
|
|
## Trademarks
|
|
|
|
|
2022-01-18 18:51:53 +03:00
|
|
|
This project may contain trademarks or logos for projects, products, or
|
|
|
|
services. Authorized use of Microsoft trademarks or logos is subject to and must
|
|
|
|
follow [Microsoft's Trademark & Brand
|
|
|
|
Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
|
|
Use of Microsoft trademarks or logos in modified versions of this project must
|
|
|
|
not cause confusion or imply Microsoft sponsorship. Any use of third-party
|
|
|
|
trademarks or logos are subject to those third-party's policies.
|