Master cURL: Essential Commands for DevOps, Monitoring, and Automation
This guide presents essential cURL commands for service health checks, API testing, file transfer, debugging, Kubernetes interactions, monitoring, load balancing, and webhook triggering, demonstrating how the versatile tool can streamline automation, CI/CD pipelines, and daily DevOps tasks.
cURL is a widely used open‑source command‑line tool for transferring data between client and server, supporting protocols such as HTTP, HTTPS, FTP, SFTP, SCP, cookies, authentication, proxies, and rate limiting.
1. Service Health Check
<code># Simple check if service is reachable
curl -I http://example.com
# Check service with authentication
curl -u username:password -I http://example.com/api/health
# Set timeout (5 seconds)
curl -m 5 -s -o /dev/null -w "%{http_code}" http://example.com
</code>2. API Testing and Interaction
<code># GET request
curl -X GET "http://api.example.com/users"
# POST JSON data
curl -X POST -H "Content-Type: application/json" \
-d '{"username":"test","password":"123"}' \
http://api.example.com/login
# Request with authorization header
curl -H "Authorization: Bearer token123" http://api.example.com/protected
</code>3. File Transfer
<code># Download file
curl -O http://example.com/file.zip
# Upload file
curl -F "[email protected]" http://example.com/upload
# FTP download
curl -u ftpuser:ftppass -O ftp://ftp.example.com/file.txt
</code>4. Debugging and Troubleshooting
<code># Verbose output
curl -v http://example.com
# Show request and response headers
curl -i http://example.com
# Follow redirects
curl -L http://example.com/redirect
</code>5. Kubernetes‑related Operations
<code># Access Kubernetes API
curl --cacert /path/to/ca.crt --cert /path/to/client.crt --key /path/to/client.key \
https://kubernetes-api-server:6443/api/v1/pods
# Access via kubectl proxy
kubectl proxy --port=8080 &
curl http://localhost:8080/api/v1/namespaces/default/pods
</code>6. Monitoring and Alerting
<code># Get Prometheus metrics
curl http://prometheus-server:9090/api/v1/query?query=up
# Send alert to Alertmanager
curl -X POST -d '{"alerts":[{"labels":{"alertname":"TestAlert"}}]}' \
http://alertmanager:9093/api/v1/alerts
</code>7. Load‑Balancing Test
<code># Multiple requests to observe load‑balancing
for i in {1..10}; do curl http://loadbalanced.example.com; done
</code>8. Webhook Triggers
<code># Trigger CI/CD pipeline
curl -X POST -H "Content-Type: application/json" \
-d '{"ref":"main"}' \
http://gitlab.example.com/api/v4/projects/1/trigger/pipeline?token=TOKEN
# Send notification to Slack
curl -X POST -H "Content-Type: application/json" \
-d '{"text":"Deployment completed"}' \
https://hooks.slack.com/services/XXXXX/YYYYY/ZZZZZ
</code>These cURL usages are valuable in automation scripts, CI/CD pipelines, service monitoring, and everyday troubleshooting.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.