E-NO
Kubernetes Service Accounts Admin networking 4 Min Read

Kubernetes Service Accounts Admin Networking Troubleshooting: A Practical Guide

calendar_today Published: 2026-08-26
update Last Updated: 2026-08-26
analytics SEO Efficiency: 100%
Technical guide illustration for Kubernetes Service Accounts Admin Networking Troubleshooting: A Practical Guide.

Intro

Kubernetes Service Accounts are the identities that Pods use to interact with the Kubernetes API and other cluster services. When Pods use these accounts, they inherit the network identity and permissions associated with them. Networking issues involving Service Accounts can manifest in several ways: a Pod may fail to reach the API server, DNS lookups may time out, or the Pod may not have the necessary permissions even though network connectivity appears fine. As an administrator, you need a systematic approach to diagnose and resolve these issues quickly.

This guide provides practical troubleshooting steps and safe diagnosis commands for Service Account networking problems in administrator contexts. You will learn how to inventory your environment, set up an isolated test pilot, run targeted connectivity and permission checks, and recover from common failures. The examples use a test namespace and a dedicated Service Account to minimize risk to production workloads. By the end, you will have a repeatable checklist to validate Service Account networking and a clear recovery plan for when things go wrong.

Version and Environment Inventory

Before troubleshooting, document the versions and topology of your Kubernetes cluster. This inventory helps you align your diagnosis with known behaviors and configuration details. Gather the Kubernetes version, container runtime, network plugin (CNI), and the Service Account details in use.

Run the following commands to collect basic cluster information:

kubectl version --short
kubectl get nodes -o wide
kubectl get serviceaccounts --all-namespaces

Expected output from kubectl version --short shows client and server versions, for example:

Client Version: v1.28.2
Server Version: v1.28.2

kubectl get nodes -o wide lists each node with its internal and external IP addresses, operating system, and container runtime version. kubectl get serviceaccounts --all-namespaces displays every Service Account across all namespaces, which is useful to identify the one you are troubleshooting.

Record these details in a table to keep track of the environment:

ComponentVersion/Details
Kubernetesv1.28.2
CNI PluginCalico v3.26.1
Container Runtimecontainerd 1.7.6
Admin Service Accountadmin-sa in kube-system

If you have multiple clusters, repeat this inventory for each one. Ensure you have the necessary permissions to inspect the cluster; typically, you need cluster-admin or a role with get and list permissions on nodes, namespaces, and serviceaccounts.

Quick check 1 of 2

What is the default ServiceAccount in every Kubernetes namespace?

Every namespace gets a 'default' ServiceAccount upon creation.

Safe Configuration Path

When testing Service Account networking, avoid making changes directly in production namespaces. Instead, create a dedicated namespace and a test Pod that uses a new Service Account. This isolates your experiments and limits the blast radius if something goes wrong.

Follow these steps to set up a safe test environment:

  1. Create a namespace for testing:
kubectl create namespace net-test
  1. Create a Service Account in that namespace:
kubectl create serviceaccount test-sa -n net-test
  1. Bind the Service Account to a role that grants sufficient permissions for the test. For example, to allow listing pods and namespaces, create a Role and RoleBinding, or use the built-in view ClusterRole if you want read-only access across the cluster. For simplicity in this guide, we use clusterrole=view to avoid over-permissioning:
kubectl create rolebinding test-sa-view \
  --clusterrole=view \
  --serviceaccount=net-test:test-sa \
  -n net-test

Alternatively, if you specifically need admin-like permissions for a broader test, you could use clusterrole=admin, but that grants write access and should be used cautiously. The view role is read-only and sufficient for connectivity checks.

  1. Run a test Pod using this Service Account. Use a lightweight image like busybox with a sleep command to keep it running:
kubectl run test-pod \
  --image=busybox:1.36 \
  --restart=Never \
  --serviceaccount=test-sa \
  -n net-test \
  -- sleep 3600
  1. Verify the Pod is running and note its IP address:
kubectl get pod test-pod -n net-test -o wide

Expected output shows the Pod with a STATUS of Running and an IP from the cluster's Pod CIDR. For example:

NAME       READY   STATUS    RESTARTS   AGE   IP               NODE
test-pod   1/1     Running   0          10s   10.244.1.5       worker-1

This dedicated test environment ensures that any network policy changes or diagnostic commands do not affect other workloads.

Verification and Diagnostics

With the test Pod running, you can now perform connectivity and permission checks. Start by verifying DNS resolution inside the Pod, then test API server connectivity using the Service Account token, and finally verify RBAC permissions.

DNS Resolution Check

DNS is a common point of failure. Kubernetes provides a cluster DNS service (usually CoreDNS) that resolves service names. From within the test Pod, query the Kubernetes default service:

kubectl exec -n net-test test-pod -- nslookup kubernetes.default

Expected output includes the cluster IP of the kubernetes service in the default namespace, for example:

Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local

If nslookup fails or times out, check the CoreDNS pods and their logs:

kubectl get pods -n kube-system -l k8s-app=kube-dns
kubectl logs -n kube-system -l k8s-app=kube-dns

Also verify the CoreDNS ConfigMap for any misconfigurations:

kubectl get configmap coredns -n kube-system -o yaml

API Server Connectivity Check

The Service Account token is mounted in the Pod at /var/run/secrets/kubernetes.io/serviceaccount/token. Use this token to authenticate to the API server. Run a simple HTTP request to the API server's /api/v1/namespaces endpoint from within the Pod:

kubectl exec -n net-test test-pod -- sh -c \
  'TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token); \
   wget -qO- --header="Authorization: Bearer $TOKEN" \
   https://kubernetes.default.svc/api/v1/namespaces'

A successful response returns a JSON object containing a list of namespaces. For example, a snippet:

{
  "kind": "NamespaceList",
  "apiVersion": "v1",
  "metadata": {
    "resourceVersion": "12345"
  },
  "items": [
    {
      "metadata": {
        "name": "default",
        ...
      }
    }
  ]
}

If the request fails with a connection error, network policies or firewall rules may be blocking access to the API server (typically port 443). If it fails with a 403 Forbidden, the Service Account may lack the necessary RBAC permissions.

RBAC Permission Check

Even if the network path is open, the Service Account may not have permission to perform certain actions. Use kubectl auth can-i to simulate the Service Account's permissions without actually making a request from the Pod:

kubectl auth can-i list pods \
  --as=system:serviceaccount:net-test:test-sa \
  -n default

Expected output is yes or no. If the output is no, inspect the RoleBindings and ClusterRoleBindings associated with the Service Account:

kubectl get rolebindings,clusterrolebindings \
  -o json | jq '.items[] | select(.subjects[]?.name == "test-sa")'

This command assumes jq is installed; alternatively, use kubectl describe on each binding.

Additional Network Diagnostics

If DNS and API checks pass but other services are unreachable, investigate network policies and service endpoints.

Check if any NetworkPolicies are applied in the test namespace:

kubectl get networkpolicies -n net-test

If policies exist, inspect their rules to see if they allow traffic from the test Pod:

kubectl describe networkpolicy <policy-name> -n net-test

Also verify that the target service has endpoints:

kubectl get endpoints <service-name> -n <namespace>

If endpoints are empty, the service selector may not match any Pods.

Quick check 2 of 2

Which scenario is NOT a typical use case for Kubernetes service accounts?

Human users typically use user accounts, not service accounts. Service accounts are for workloads and automation.

Failure Modes and Recovery

Several common failure modes can affect Service Account networking. Here are the most frequent ones, along with diagnostic steps and recovery actions.

DNS Misconfiguration

Symptoms: nslookup fails, or returns a different IP than expected. Pods may report could not resolve host.

Diagnosis:

  • Check CoreDNS pods status.
  • Review CoreDNS logs for errors.
  • Inspect the CoreDNS ConfigMap for any custom changes.

Recovery:

  • If CoreDNS pods are crashing, restart them: kubectl rollout restart deployment coredns -n kube-system.
  • If the ConfigMap is misconfigured, correct it and restart CoreDNS.

Blocked Port 443

Symptoms: API server connectivity test fails with Connection refused or Connection timed out.

Diagnosis:

  • Check firewall rules on nodes or cloud provider security groups that may block port 443 from Pod IPs.
  • Check NetworkPolicies that may deny egress to the API server.

Recovery:

  • Adjust firewall rules to allow Pod-to-API-server traffic on port 443.
  • Modify or remove restrictive NetworkPolicies.

Insufficient RBAC Permissions

Symptoms: API request returns 403 Forbidden even though network connectivity is fine.

Diagnosis:

  • Use kubectl auth can-i --as=system:serviceaccount:<namespace>:<sa> to test permissions.
  • Inspect RoleBindings and ClusterRoleBindings.

Recovery:

  • Grant the necessary permissions by creating or updating RoleBindings. For example:
kubectl create rolebinding test-sa-view \
  --clusterrole=view \
  --serviceaccount=net-test:test-sa \
  -n net-test

If you need to remove permissions, delete the binding:

kubectl delete rolebinding test-sa-view -n net-test

Service Account Token Not Mounted

Symptoms: Pod fails to start or the token file is missing at /var/run/secrets/kubernetes.io/serviceaccount/token.

Diagnosis:

  • Describe the Pod to see events: kubectl describe pod test-pod -n net-test.
  • Check if the Service Account exists and is correctly referenced.

Recovery:

  • Ensure the Service Account exists: kubectl get serviceaccount test-sa -n net-test.
  • If not, create it and restart the Pod.

Rollback and Cleanup

Whenever you make changes for testing, have a recovery plan. Document the original configuration before modifying any resource. Use version control for manifests to track changes. To clean up the test environment:

kubectl delete namespace net-test

This deletes all resources in that namespace, including the test Pod, Service Account, and RoleBindings.

Operations Checklist

Use the following checklist for routine Service Account networking operations to ensure consistent and secure configuration. Replace the example values with your actual details.

CheckCommandExpected Result
Service Account existskubectl get serviceaccount test-sa -n net-testShows the Service Account
RoleBinding existskubectl get rolebinding -n net-testLists the binding with correct subject
DNS resolution from Podkubectl exec -n net-test test-pod -- nslookup kubernetes.defaultReturns service IP (e.g., 10.96.0.1)
API connectivity with tokenkubectl exec -n net-test test-pod -- sh -c 'TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token); wget -qO- --header="Authorization: Bearer $TOKEN" https://kubernetes.default.svc/api/v1/namespaces'Returns JSON list of namespaces
Permission checkkubectl auth can-i list pods --as=system:serviceaccount:net-test:test-sa -n defaultyes
NetworkPolicies in namespacekubectl get networkpolicies -n net-testNone, or expected policies
Endpoints for servicekubectl get endpoints kubernetes -n defaultShows API server IP and port
CoreDNS statuskubectl get pods -n kube-system -l k8s-app=kube-dnsAll pods Running

Additionally, monitor authentication errors in the API server logs for repeated failures from a specific Service Account:

kubectl logs -n kube-system <apiserver-pod-name> | grep "forbidden"

Replace <apiserver-pod-name> with the actual API server Pod name.

Conclusion

Troubleshooting Kubernetes Service Account admin networking requires a systematic approach: inventory your environment, set up a safe test pilot, run targeted diagnostics, and understand the common failure modes with clear recovery actions. This guide has provided concrete commands and examples for checking DNS, API connectivity, RBAC permissions, and network policies. By following the checklist, you can quickly identify and resolve networking issues, ensuring reliable and secure cluster operations.

Remember to always isolate your tests in a dedicated namespace, use least-privilege Service Accounts, and have a rollback plan. Document any changes you make to the cluster configuration so that you can revert if needed. Start with the safe configuration path described here to minimize risk and build confidence before applying changes to production workloads.

With these practices, you can reduce downtime and maintain a well-functioning Kubernetes networking environment.

Related Research

Article Quality Score

Reader usefulness 100%
  • check_circle Reader-ready guide
  • check_circle Practical examples included
  • check_circle Clean SEO article URL