Connect CLI tools to a cluster¶
Select a Kubernetes context and verify that kubectl and kn can read Knative Services in the intended namespace. This guide does not install Knative or provision cluster credentials.
Prerequisites¶
kubectlandknare installed.- You have a kubeconfig file and any credential helper required by your cluster provider.
- Knative Serving is installed on the target cluster.
- Your account can list Knative Services in the target namespace.
Do not run resource-changing commands until you have confirmed the cluster and namespace. A context selects both cluster connection details and credentials.
Select the connection¶
-
By default, the tools use
$HOME/.kube/config. If your kubeconfig is elsewhere, set its path for this shell:export KUBECONFIG=/path/to/kubeconfigReplace the example path with your file. Obtain credentials from your cluster administrator or provider if you do not have a kubeconfig; see provider guidance.
-
List the available contexts:
kubectl config get-contextsFind the context for the intended cluster. The
CURRENTmarker identifies the default context, but the next steps select a context explicitly rather than changing that default. -
Set the context and namespace for the checks:
CONTEXT=my-cluster-context NAMESPACE=defaultReplace both example values with the context name and namespace you intend to use.
Verify access¶
Read Services with both tools using the same context and namespace:
kubectl --context "$CONTEXT" get services.serving.knative.dev -n "$NAMESPACE"
kn service list --context "$CONTEXT" --namespace "$NAMESPACE"
Both commands should list the same Knative Services. An empty list or No resources found is a valid result if the namespace has no Services. Successful reads verify the connection and list permission, not permission to create or update resources.
If the checks fail:
- A context-not-found error means the selected name is not in the loaded kubeconfig. Check
KUBECONFIGand the context list. - Authentication or credential-helper errors require renewing credentials or installing the provider's helper.
- A
Forbiddenresponse means you reached the API server but do not have the required permission. Ask the cluster administrator for access to the intended namespace. - A missing Knative Service resource type can mean Serving is not installed on this cluster. Confirm the context before asking the administrator to check the installation.
- A connection or timeout error requires checking the API-server address and network access with your cluster administrator.
Continue using the explicit context and namespace on subsequent commands if you do not want to rely on defaults. For supported command flags, consult the kn command reference.
Kubeconfig versus kn configuration¶
A kubeconfig supplies cluster connection details and credentials. The separate kn configuration file supplies CLI preferences such as plugin and sink mappings. kn --config selects that preferences file; it is not a substitute for --kubeconfig or KUBECONFIG.
See Customizing kn for the configuration-file reference, and Organizing Cluster Access Using kubeconfig Files for Kubernetes' kubeconfig rules.
Using kubeconfig files with your platform¶
Provider-specific instructions for obtaining or updating kubeconfig:
- Amazon EKS
- Google GKE
- IBM IKS
- Red Hat OpenShift Cloud Platform
- minikube — starting minikube writes a kubeconfig or adds a context to an existing file.