|
1 | 1 | ---
|
2 | 2 | meta:
|
3 |
| - title: How to connect to a cluster with kubectl |
| 3 | + title: How to connect to a Kubernetes Kapsule cluster with kubectl |
4 | 4 | description: Learn how to connect to a Kubernetes cluster using kubectl. Follow steps to manage cluster resources, deploy applications, and view logs easily from your local computer.
|
5 | 5 | content:
|
6 |
| - h1: How to connect to a cluster with kubectl |
7 |
| - paragraph: This page explains how to connect to a Kubernetes cluster via kubectl |
| 6 | + h1: How to connect to a Kubernetes Kapsule cluster with kubectl |
| 7 | + paragraph: This guide details the steps to connect to a Kubernetes cluster using kubectl, the Kubernetes command-line tool. |
8 | 8 | tags: connection cluster kubectl
|
9 | 9 | dates:
|
10 |
| - validation: 2024-11-18 |
| 10 | + validation: 2025-01-15 |
11 | 11 | posted: 2020-09-20
|
12 | 12 | categories:
|
13 | 13 | - kubernetes
|
14 | 14 | ---
|
15 | 15 |
|
16 |
| -Once your [cluster is created](/containers/kubernetes/how-to/create-cluster/), a `.kubeconfig` file is available for download to manage several Kubernetes clusters. You can use this with `kubectl`, the Kubernetes command line tool, allowing you to run commands against your Kubernetes clusters. You can use `kubectl` from a terminal on your local computer to deploy applications, inspect and manage cluster resources, and view logs. |
| 16 | +Once your [cluster is created](/containers/kubernetes/how-to/create-cluster/), you can install a `kubeconfig` file unsing Scaleway's command-line tool on your local machine to manage your Kubernetes cluster. |
| 17 | + |
| 18 | +You can use this with `kubectl`, the Kubernetes command-line tool, allowing you to run commands against your Kubernetes cluster. This enables you to deploy applications, inspect and manage cluster resources, and view logs directly from your local machine. |
17 | 19 |
|
18 | 20 | <Macro id="requirements" />
|
19 | 21 |
|
20 |
| -- A Scaleway account logged into the [console](https://console.scaleway.com) |
21 |
| -- [Owner](/identity-and-access-management/iam/concepts/#owner) status or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) allowing you to perform actions in the intended Organization |
22 |
| -- Created a [Kubernetes Kapsule cluster](/containers/kubernetes/how-to/create-cluster/) |
| 22 | +- A [Scaleway account](https://console.scaleway.com) logged into the console. |
| 23 | +- [Owner status](https://console.scaleway.com) or [IAM permissions](/identity-and-access-management/iam/concepts/#permission) to perform actions in the intended Organization. |
| 24 | +- A [Kubernetes Kapsule cluster](/containers/kubernetes/how-to/create-cluster/) created. |
| 25 | +- [kubectl](https://kubernetes.io/docs/tasks/tools/) installed locally. |
| 26 | +- The [Scaleway CLI](/developer-tools/scaleway-cli/quickstart/) installed locally. |
| 27 | + |
| 28 | +## Setting fine-grained permissions (IAM Policies) for Kubernetes access |
| 29 | + |
| 30 | +If your Organization uses IAM to control access, ensure that you or your group/application has the following permission sets assigned at the Project scope: |
| 31 | + |
| 32 | +- `KubernetesFullAccess` (or `KubernetesReadOnly`, depending on your needs): |
| 33 | + Grants you the ability to manage (or list/read) Kubernetes clusters, nodes, and related actions in your Scaleway Project. |
| 34 | + |
| 35 | +To create a new policy with the correct permission sets, follow these steps: |
| 36 | + |
| 37 | +### Key elements of IAM Policy configuration |
| 38 | + |
| 39 | +1. **Create a new policy**: Navigate to the **Policies** tab in your Organization’s IAM console and create a new policy. |
| 40 | +2. **Add your user (or group/application)**: Assign your user, group, or application as the **Principal**. |
| 41 | +3. **Add an IAM rule**: |
| 42 | + - **Scope**: Set to **Access to resources** and specify the desired Project(s). |
| 43 | + - **Permission Sets**: Include the following as needed: |
| 44 | + - `KubernetesFullAccess` for full cluster management. |
| 45 | + - `KubernetesReadOnly` for read-only access. |
| 46 | +4. Click **Validate** and then **Create Policy**. |
| 47 | + |
| 48 | +Refer to our [policy and permission sets documentation](/identity-and-access-management/iam/reference-content/permission-sets/) for more details. |
| 49 | + |
| 50 | +## Accessing the cluster |
| 51 | + |
| 52 | +You can use the Scaleway CLI to retrieve (and merge) your `kubeconfig` file automatically, then interact with your Kubernetes cluster. |
23 | 53 |
|
24 |
| -1. [Install kubectl](https://kubernetes.io/docs/tasks/tools/) on your local computer. |
25 |
| -2. Download the `.kubeconfig` files from your cluster's **overview** page: |
26 |
| - <Lightbox src="scaleway-kapsule_kubeconfig.webp" alt="" /> |
27 |
| -3. Configure access to your cluster. You can do this in one of two ways: |
| 54 | +### Install and configure the Scaleway CLI |
28 | 55 |
|
29 |
| - Set the `KUBECONFIG` environment variable: |
30 |
| - ``` |
31 |
| - export KUBECONFIG=/$HOME/Downloads/Kubeconfig-ClusterName.yaml |
32 |
| - ``` |
| 56 | +If you have not set up the Scaleway CLI yet: |
33 | 57 |
|
34 |
| - Or use `use $HOME/.kube/config file`: |
35 |
| - ``` |
36 |
| - mv $HOME/Downloads/Kubeconfig-ClusterName.yaml $HOME/.kube/config |
37 |
| - ``` |
| 58 | +1. Follow our [installation guide](/developer-tools/scaleway-cli/quickstart) for platform-specific instructions using Homebrew, Chocolatey, or manual methods. |
| 59 | +2. Run the following command and follow the prompts to set up your CLI with your Scaleway API keys: |
| 60 | + ```bash |
| 61 | + scw init |
| 62 | + ``` |
| 63 | + You will need your [API Key](https://identity-and-access-management/iam/how-to/#creating-API-keys) (Access Key & Secret Key). |
38 | 64 |
|
39 |
| - Either way, make sure you replace `/$HOME/Downloads/Kubeconfig-ClusterName.yaml` with the correct name and path of your downloaded `.kubeconfig` file. |
40 |
| -4. Run the following command to finish: |
41 |
| - ``` |
42 |
| - kubectl get nodes |
43 |
| - ``` |
| 65 | +### Retrieve and install the kubeconfig using `scw` |
44 | 66 |
|
| 67 | +1. Run the following command to install the kubeconfig file for your cluster: |
| 68 | + ```bash |
| 69 | + scw k8s kubeconfig install <cluster-id> |
| 70 | + ``` |
| 71 | + This command will: |
| 72 | + - Download the `kubeconfig` for the specified cluster. |
| 73 | + - Merge it into your existing kubeconfig file (default location: `~/.kube/config`). |
45 | 74 |
|
| 75 | +2. Verify the installation: |
| 76 | + ```bash |
| 77 | + kubectl get nodes |
| 78 | + ``` |
| 79 | + A list of nodes from your Kapsule cluster should appear. If not, review the troubleshooting section. |
0 commit comments