Quick Start
This document will help you quickly understand how to create a kubernetes connector to connect to a kubernetes cluster and perform kubectl operations securely without directly handling credentials.
TOC
Estimated Reading TimePrerequisitesProcess OverviewSteps to OperateStep 1: Create NamespaceStep 2: Create K8S Credentials and ConnectorStep 3: Create a Job to Perform Kubectl OperationsStep 4: Verify OperationWhat happens under the hoodKey ObservationsProxy Configuration FieldsAuthentication FlowKubeconfig VolumeTroubleshootingFurther ReadingReferencesEstimated Reading Time
15 minutes
Prerequisites
- Kubernetes cluster with Connectors system installed (Operator, Core and K8S components). See the Installation Guide for details on installing these components.
- kubernetes cluster apiserver address and bearer token has list kubernetes pod permission
- Basic knowledge of Kubernetes
Process Overview
Steps to Operate
Step 1: Create Namespace
Create a dedicated namespace for this demonstration:
Step 2: Create K8S Credentials and Connector
Create both the Secret containing k8s credentials and the kubernetes connector resource. For more detailed information about creating and configuring connectors, please refer to the Connectors Quick Start Guide.
Verify that the connector is in "Ready" status:
The output should show:
Step 3: Create a Job to Perform Kubectl Operations
Create a job that uses the connector to perform k8s operations:
Key parameters in volumeAttributes:
connector.name: The name of your kubernetes connectorconfiguration.names: Set to "kubeconfig", which references a specific configuration template defined in the kubernetes connectorClass. This template is used to generate the ".kubeconfig" file with the appropriate settings for authentication.
Step 4: Verify Operation
Check the job's logs to confirm the kubectl operations were successfully performed:
You should see the kubectl operations completing successfully and list all pods in the cluster without any secret configuration in the job.
What happens under the hood
The kubernetes connector works by:
- Creating a proxy service that sits between your workloads and the target k8s cluster
- Injecting authentication information when requests pass through the proxy
- Providing
kubeconfigfiles for client to perform kubectl operations with the proxy
To demonstrate this mechanism, let's inspect the generated kubeconfig file:
View the generated kubeconfig file:
Example output:
Key Observations
- The
serverfield matches the Kubernetes API server address specified in the Connector - Additional proxy related fields enable proxy-based authentication, like
cluster.proxy-urlandcluster.certificate-authority-data. - The
kubeconfigfile contains no original bearer tokens and mount to the Pod via Connectors CSI Driver.
Proxy Configuration Fields
-
cluster.proxy-url: The connector proxy address fromstatus.proxy.httpAddressfield in the connector namedk8s-connector:The output should show:
the
cluster.proxy-urlcontains the proxy authentication information:- username:
<connector-namespace>/<connector-name>format, the connector namespace and name - password: Temporary ServiceAccount token automatically generated by the connector (expires after 30 minutes) (not the original k8s cluster token)
- username:
-
cluster.certificate-authority-data: CA certificate data for proxy server TLS validation, the client should trust the proxy server's certificate.
Authentication Flow
The inspect-k8s-access pod contains no original cluster tokens. When kubectl makes HTTPS requests to the Kubernetes API server, the proxy server intercepts these requests, injects authentication credentials from the k8s-connector, and forwards the authenticated requests to the backend API server.
Kubeconfig Volume
The kubeconfig file is mounted into the Pod via Connectors CSI Driver.
For volumes parameters, please refer to Using Connectors CSI Driver to mount kubeconfig file in Kubernetes Connector Concepts document.
Troubleshooting
If your kubectl operation fails, check the following:
-
Connector Status: Ensure the connector is in "Ready" state:
-
Verify the connectors deployment status: ensure all components are deployed and in "Ready" state
Further Reading
After successfully performing kubectl operations using the kubernetes connector, you can:
- Change kubectl command to what you want, like
kubectl create,kubectl apply - Learn more about Concepts of Kubernetes Connectors
- Using Kubernetes Connectors in CI/CD pipelines