Usage of Kubectl Create in Deploying K8S Resources
The kubectl create command is an imperative way of deploying resources on a Kubernetes cluster . The following are a few popular resources that can be created using kubectl create command.
Kubectl create – Creating Deployment Resource
Creating a deployment resource imperatively with kubectl create command by default replicas count will be 1.
Syntax:
kubectl create deployment <Deployment-Name> --image <Container-Image>
Example
kubectl create deployment demo-deployment --image nginx:latest
The following screenshot shows the practical usage of creating imperative Deployment with kubectl create :
kubectl create – Creating Namespace Resource
Kubernetes Namespaces are used for logically isolate the resources within a cluster. By default, a namespace is already created in a cluster i.e “Default”. It is very useful to isolated the resources and its management when you are working with different projects or different teams working in same same cluster.
The following command is used to list all namespaces that are created in the cluster.
kubectl get ns
Syntax
kubectl create namespace <namespace_name>
( OR )
kubectl create -n <namespace_name>
Example
kubectl create namespace "production"
The following screenshot shows the practically creating a namespace imperatively with kubectl create command.
Kubectl create – Creating ServiceAccount Resource
A Kubernetes ServiceAccount is used as an identity for assigning to pods or applications. It enables the resources to interact with the Kubernetes API and access the resources within the cluster, while managing permissions through Role-Based Access Control (RBAC).
Syntax
kubectl create serviceaccount <ServiceAccount_name>
Example
kubectl create serviceaccount "demo-user"
The following screenshot help you in creating the serviceaccount imperatively with kubectl create command.
Kubectl create – Creating Secret Resource
A Kubernetes Secret is a resource used to securely store the sensitive data such as passwords or API keys of the applications. It provides a proper way of management and distribution of confidential data to resources within the Kubernetes cluster.
Syntax
kubectl create secret <Secret-Type> <Secret-Name>
Example
kubectl create secret genric "demo-user-secret"
The following screenshot help you in creating a secret resource of generic type imperatively with kubectl create command.
Kubernetes – Kubectl Create and Kubectl Apply
Kubernetes is an open-source Container Orchestrating software platform that is widely used in modern application deployment and management. It comes up with many internal resources to manage the other working nodes Organizing as a Cluster facilitates seamless automatic scaling, and deployment updates making applications highly available and fault tolerant. The `kubectl create` and `kubectl apply` commands are essential for managing containerized applications effectively. This Article involves discussing these two kubectl commands with their method of approaches in deploying the resources.