The kubectl create
command in Kubernetes is used to create resources based on the configuration provided either from files or directly from stdin. This command is essential for deploying applications and managing the infrastructure in Kubernetes clusters efficiently.
Here are several examples demonstrating how to use kubectl create
with different Kubernetes resource configurations:
Example 1: Creating a Pod from a YAML file
Suppose you have a YAML file named pod.yaml
describing a Kubernetes Pod. You can create this Pod using:
kubectl create -f pod.yaml
To verify if the Pod has been created, you can check its status using:
kubectl get pods
Example 2: Creating a Deployment from stdin
You can directly create a Deployment without using a file by passing the configuration via stdin:
cat <Verify the Deployment creation by checking its status:
kubectl get deploymentsExample 3: Creating a Service using imperative command
You can create a Kubernetes Service imperatively without using a file:kubectl create service clusterip my-service --tcp=80:8080Verify the Service creation:
kubectl get servicesExample 4: Creating a ConfigMap from YAML
Create a ConfigMap using a YAML file:kubectl create -f configmap.yamlVerify the ConfigMap creation:
kubectl get configmapExample 5: Creating a Secret from a literal value
You can create a Secret by passing literal values directly:kubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=secretpasswordVerify the Secret creation:
kubectl get secretsExample 6: Creating a Namespace
Create a new Kubernetes Namespace:kubectl create namespace my-namespaceVerify the Namespace creation:
kubectl get namespacesExample 7: Creating a PersistentVolumeClaim
Create a PersistentVolumeClaim (PVC) from a YAML file:kubectl create -f pvc.yamlVerify the PVC creation:
kubectl get pvcExample 8: Creating a Job from YAML
Create a Kubernetes Job using a YAML file:kubectl create -f job.yamlVerify the Job creation:
kubectl get jobsExample 9: Creating a CronJob from YAML
Create a CronJob in Kubernetes from a YAML file:kubectl create -f cronjob.yamlVerify the CronJob creation:
kubectl get cronjobsExample 10: Creating a HorizontalPodAutoscaler
Create a HorizontalPodAutoscaler (HPA) using a YAML file:kubectl create -f hpa.yamlVerify the HPA creation:
kubectl get hpaAlso check similar articles.
Overriding --databases Option in mysqldump
Creating Tab-Separated Output Files with mysqldump
Handling Failed SSL Session Data Reuse in mysqldump
Setting SSL Session Data File in mysqldump
Setting TLS 1.3 Cipher in mysqldump
Discussion about this post