- Home
- Operations Guide
- Deploy applications with Kubernetes
- Create a service account for a Kubernetes app
Create a service account for a Kubernetes app#
Kubernetes uses service accounts to enable workload access control.
A service account is an identity for processes that run in a Pod. When
a process is authenticated through a service account, it can contact the API
server and access cluster resources. The default service account is
default.
You provide a service account with access to cluster resources by creating a role binding, just as you do for users and teams.
This example illustrates how to create a service account and role binding used with an NGINX server.
To create a Kubernetes namespace:
It is necessary to create a namespace for use with your service account, as unlike user accounts, service accounts are scoped to a particular namespace.
-
Log in to the MKE web UI.
-
In the left-side navigation panel, navigate to Kubernetes > Namespaces and click Create.
-
Leave the Namespace drop-down blank.
-
Paste the following in the Object YAML editor:
apiVersion: v1 kind: Namespace metadata: name: nginx -
Click Create.
-
Navigate to the
nginxnamespace. -
Click the vertical ellipsis in the upper-right corner and click Set Context.
To create a service account:
-
In the left-side navigation panel, navigate to Kubernetes > Service Accounts and click Create.
-
In the Namespace drop-down, select nginx.
-
Paste the following in the Object YAML editor:
apiVersion: v1 kind: ServiceAccount metadata: name: nginx-service-account -
Click Create.
There are now two service accounts associated with the nginx namespace: default and nginx-service-account.
To create a role binding:
To give the service account access to cluster resources, create a role binding
with view permissions.
-
From the left-side navigation panel, navigate to Access Control > Grants.
Note
If Hide Swarm Navigation is selected on the
> Admin Settings > Tuning page, Grants will display as Role Bindings under the Access Control menu item. -
In the Grants pane, select the Kubernetes tab and click Create Role Binding.
-
In the Subject pane, under SELECT SUBJECT TYPE, select Service Account.
-
In the Namespace drop-down, select nginx.
-
In the Service Account drop-down, select nginx-service-account and then click Next.
-
In the Resource Set pane, select the nginx namespace.
-
In the Role pane, under ROLE TYPE, select Cluster Role and then select view.
-
Click Create.
The NGINX service account can now access all cluster resources in the nginx
namespace.