  def _GetK8sApiClient(self) -> client.ApiClient:
    """Builds an authenticated Kubernetes API client.

    This method builds a kubeconfig file similarly to
    `gcloud container clusters get-credentials CLUSTER_NAME`, and then
    creates a Kubernetes API client from it. This API client can then be
    used in the Kubernetes classes

    Returns:
      client.ApiClient: An authenticated Kubernetes API client.
    """
    # Retrieve cluster information via GKE API
    get_op = self.GetOperation()
    # Extract fields for kubeconfig
    ca_data = get_op['masterAuth']['clusterCaCertificate']
    # Context string is built the same way that gcloud does
    # in get-credentials
    context = '_'.join([
        'gke',
        self.project_id,
        self.location,
        self.name,
    ])
    # Build kubeconfig dict and load
    kubeconfig = client.Configuration()
    loader = kube_config.KubeConfigLoader({
        'apiVersion': self.GKE_API_VERSION,
        'current-context': context,
        'clusters': [{
            'name': context,
            'cluster': {
                'certificate-authority-data': ca_data,
                'server': 'https://{0:s}'.format(get_op['endpoint']),
            }
        }],
        'contexts': [{
            'name': context, 'context': {
                'cluster': context, 'user': context
            }
        }],
        'users': [{
            'name': context, 'user': {
                'auth-provider': {
                    'name': 'gcp'
                }
            }
        }]
    })
    loader.load_and_set(kubeconfig)
    return client.ApiClient(kubeconfig)
Builds an authenticated Kubernetes API client.

This method builds a kubeconfig file similarly to
`gcloud container clusters get-credentials CLUSTER_NAME`, and then
creates a Kubernetes API client from it. This API client can then be
used in the Kubernetes classes

Returns:
client.ApiClient: An authenticated Kubernetes API client.
libcloudforensics/providers/gcp/internal/gke.py