1. Answers
  2. How To Make A Kubernetes Service Account For V124?

How to Make a Kubernetes Service Account for V124?

Introduction

In this guide, we will create a Kubernetes Service Account using Pulumi in TypeScript. A Service Account in Kubernetes provides an identity for processes that run in a Pod. This identity can be used to access the Kubernetes API and perform actions within the cluster.

Step-by-Step Explanation

Step 1: Install Pulumi and Dependencies

First, ensure you have Pulumi installed. If not, you can install it using the following command:

npm install -g pulumi

Next, create a new Pulumi project if you don’t already have one:

pulumi new typescript

Step 2: Install Kubernetes Provider

Add the Pulumi Kubernetes provider to your project:

npm install @pulumi/kubernetes

Step 3: Create the Service Account

In your index.ts file, add the following code to create a Kubernetes Service Account:

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

const sa = new k8s.core.v1.ServiceAccount("my-service-account", {
    metadata: {
        name: "my-service-account",
        namespace: "default",
    },
});

export const saName = sa.metadata.name;

Step 4: Deploy the Service Account

Run the following commands to deploy the Service Account to your Kubernetes cluster:

pulumi up

Summary

In this guide, we created a Kubernetes Service Account using Pulumi in TypeScript. We started by installing Pulumi and the Kubernetes provider, then we wrote the code to define the Service Account, and finally, we deployed it to the cluster using pulumi up. This Service Account can now be used by Pods to interact with the Kubernetes API.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";

const sa = new k8s.core.v1.ServiceAccount("my-service-account", {
    metadata: {
        name: "my-service-account",
        namespace: "default",
    },
});

export const saName = sa.metadata.name;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up