[Yandex Cloud documentation](../../../index.md) > [Yandex Managed Service for Kubernetes](../../index.md) > [Step-by-step guides](../index.md) > Connecting to a cluster > Connection method overview

# Connection method overview

You can connect to a [Managed Service for Kubernetes cluster](../../concepts/index.md#kubernetes-cluster) in the following ways:
* Over the internet if you configured public access to the cluster [when creating it](../kubernetes-cluster/kubernetes-cluster-create.md).
* From Yandex Cloud virtual machines located in the same [cloud network](../../../vpc/concepts/network.md).

To connect to a cluster, you can use:
* [kubectl](#kubectl-connect)
* [Static configuration file](#static-conf-connect)

To connect to cluster nodes, follow the steps in [Connecting to a node over SSH](../node-connect-ssh.md).

{% note tip %}

For integration with GitLab, we recommend using the GitLab Runner application installed in the cluster. Learn more in [Continuous deployment of containerized applications using GitLab](../../tutorials/gitlab-containers.md).

{% endnote %}

## Configuring security groups {#configuring-security-groups}

[Security groups](security-groups.md) may block cluster connections. To manage a cluster using `kubectl`, you must have rules in security groups that allow access to the Kubernetes API. If you need a step-by-step guide on setting up rules, see [Rules to access the Kubernetes API](security-groups.md#rules-master).

## Connecting to a cluster {#kubectl-connect}

When connecting to a Kubernetes cluster, the user [logs in to Yandex Identity and Access Management](../../../iam/concepts/authorization/index.md) and gets access permissions based on the [assigned role](../../security/index.md#yc-api). To log in, install the [Yandex Cloud command-line interface (CLI)](../../../cli/quickstart.md).

If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

To connect to your cluster:

1. Install [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl).

1. Add credentials to the `kubectl` configuration file depending on the type of IP address of the cluster you are connecting to:

   {% list tabs %}

   - Public IP address

      To get credentials to connect to the cluster's public IP address from the internet, run this command:

      ```bash
      yc managed-kubernetes cluster \
         get-credentials <cluster_name_or_ID> \
         --external
      ```

      You can also view the connection command in the [management console](https://console.yandex.cloud) on the cluster page under **Access**.

      If you [created your cluster](../kubernetes-cluster/kubernetes-cluster-create.md#kubernetes-cluster-create) without a public IP address, you can only connect to this cluster using its internal IP address.

   - Internal IP address

      To get credentials to connect to the cluster's internal IP address from a VM located in the same network, run this command:

      ```bash
      yc managed-kubernetes cluster \
         get-credentials <cluster_name_or_ID> \
         --internal
      ```

      You can also view the connection command in the [management console](https://console.yandex.cloud) on the cluster page under **Access**.

   {% endlist %}

   {% note info %}

   By default, credentials are added to the `$HOME/.kube/config` file. If you need to change the configuration location, use the `--kubeconfig <file_path>` parameter.

   {% endnote %}

1. Make sure the cluster is accessible:

   ```bash
   kubectl cluster-info
   ```

   If `kubectl` is configured correctly, the command will return cluster information.

## Connecting using a static configuration {#static-conf-connect}

If you cannot use the Yandex Cloud CLI for some reason, [connect to a cluster using static configuration files](create-static-conf.md).