Connecting to Kubernetes

To connect to a Kubernetes cluster and use kubectl via strongDM, there are three steps:

  1. Ensure you have been granted access to at least one Kubernetes cluster by your strongDM administrator

  2. Click on the menu icon in the upper right of your GUI and select update kubectl configuration. For CLI users, run sdm k8s update-config. This will add SDM-specific sections to your existing ~/.kube/config file or create a new one if it doesn’t yet exist.

    Note: If this command fails, please see the section below labeled Manual Configuration Update.

  3. Click to connect to the Kubernetes cluster in the GUI, or run sdm connect <k8s name> from the command line.

Once you have updated your kubectl configuration and connected, you should be able to run kubectl commands directly on the SDM-managed clusters.

$ kubectl get pods
NAME                                     READY     STATUS    RESTARTS   AGE
imprecise-bunny-mysql-6b65b5ff54-wflb9   1/1       Running   0          38d
imprecise-bunny-mysql-test               0/1       Pending   0          17d
redis-master-6b464554c8-9w7k8            1/1       Running   0          34d
shell-demo                               1/1       Running   0          39d

Manual Configuration Update

If the update kubectl configuration command fails, it is likely because you are using a separate Kubernetes configuration manager. In this case, you can manually update your ~/.kube/config file as follows.

  1. For each Kubernetes cluster you wish to configure, record its port as reported in the web UI or sdm status.

  2. Add the following sections to your config file for each cluster:

    1. A cluster item:

       - cluster:
         server: http://localhost:<port>
         name: cluster-name
      
    2. A context item:

       - context:
         cluster: sdm-k8s-1
         user: sdm-user
         name: strongDM Kubernetes 1
      
  3. Add a single user item for the sdm-user name:

     - name: sdm-user
       user: {}
    
  4. Save and exit the editor. At this point you should be able to switch contexts to a strongDM cluster and connect normally.

Example

The following is an example of a kubectl configuration file with two strongDM-managed clusters.

apiVersion: v1
clusters:
- cluster:
  server: http://localhost:<port1>
  name: sdm-k8s-1
- cluster:
  server: http://localhost:<port2>
  name: sdm-k8s-2
contexts:
- context:
  cluster: sdm-k8s-1
  user: sdm-user
  name: strongDM Kubernetes 1
- context:
  cluster: sdm-k8s-2
  user: sdm-user
  name: strongDM Kubernetes 2
current-context: strongDM Kubernetes 1
kind: Config
preferences: {}
users:
- name: sdm-user
  user: {}

If you have any questions or problems, please contact support@strongdm.com for assistance.