π How to Apply YAML Configurations Using kubectl in Terminal
In this blog post, I'll show you how to correctly paste and apply a YAML configuration into your terminal using kubectl. It's an easy and efficient method using the cat command with a here document (<<EOF). Letβs dive in! π
π Step-by-Step Guide
1οΈβ£ Copy the YAML Configuration
Hereβs a sample YAML configuration for creating an Elasticsearch resource:
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
namespace: elasticsearch
spec:
version: 7.10.0
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
2οΈβ£ Paste the Configuration in Terminal
Use the cat command with a here document to apply this YAML configuration directly in your terminal. Here's how:
@rifaterdemsahin β /workspaces/OpenShiftEventRouter (main) $ cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
namespace: elasticsearch
spec:
version: 7.10.0
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
EOF
@rifaterdemsahin β /workspaces/OpenShiftEventRouter (main) $
3οΈβ£ Run the Command
Once pasted, press Enter, and the configuration will be applied to your Kubernetes cluster. This will create the Elasticsearch resource as defined in the YAML.
β¨ Key Tips
-
π Ensure you have the necessary permissions to apply resources in your Kubernetes cluster.
-
βοΈ Verify that your
kubectlis configured and pointing to the correct cluster (kubectl config viewis your friend!). -
π¦ Validate the creation using
kubectl get elasticsearch -n elasticsearch.

π Before applying:
πΈ Take a screenshot of your terminal right after pasting the command to verify your configuration.
π After applying:
πΈ Capture the output from kubectl get commands to confirm the resource has been created successfully.
π‘ Why Use cat <<EOF?
-
π οΈ Convenience: Paste and apply YAML configurations without creating temporary files.
-
π Efficiency: Reduces steps, keeping everything in your terminal.
-
π― Portability: Easily share and execute configurations in collaborative environments.
π Connect with me:
πΌ LinkedIn
π¦ Twitter
π₯ YouTube
π» GitHub
π£ Let me know how this guide helped you! π
Imported from rifaterdemsahin.com Β· 2025