Crab 🦀
Dynamic configuration file templating tool for kubernetes manifest or general configuration files
How to install
Download according to your computer architecture at release page go to release page
OS |
Platform |
Status |
Ubuntu, Debian |
amd64, arm64, 386 |
available |
MacOS, Darwin |
amd64, arm64, 386 |
available |
Windows |
amd64, arm64, 386 |
available |
Extract using command like :
tar -xzf crab-cli-v0.1.0-darwin-amd64.tar.gz -C crab
Move to /usr/local/bin (Optional) :
cp crab/crab /usr/local/bin
Then check crab cli working properly :
Build From Source
- clone this repository
- make sure you have go version 18
- run
make build
How to use
basic command fromat :
crab -f <fileinputpath> -r <keyvalue> -o <outputfilepath>
Flags :
Flag |
Description |
Required |
default |
-f |
file input path location eg. ./manifest/nginx.yaml (accept any config file ext, .env, json, yml, yaml etc.) |
true |
- |
-o |
write output file location eg. ./manifest/nginx-result.yaml |
false |
same as input file path (overwrite) |
-r |
key value replacable |
true |
- |
-q |
key value replacable with quotes |
false |
- |
-v |
verbose process |
false |
false |
Case 1 Standart replace
First add {{replacableName}} to your file :
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: {{namespace}}
spec:
ports:
- targetPort: 80
name: nginxhttp
port: {{exposePort}}
crab cli will replace {{replacableName}} as the key, based on the example above :
- {{namespace}}
- {{exposePort}}
then run crab command :
crab -f inputfile.yaml -r namespace=production -r exposePort=8081
yes you can override multiple key values ✔️
write output to another file add -o flag:
crab -f inputfile.yaml -r namespace=production -r exposePort=8081 -o result.yaml
to make verbose add -v flag:
crab -f inputfile.yaml -r namespace=production -r exposePort=8081 -o result.yaml -v
verbose output :
[REPLACED] from namespace to production
[REPLACED] from exposePort to 8081
[DONE] Crab output result at result.yaml
the result will be :
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: production
spec:
ports:
- targetPort: 80
name: nginxhttp
port: 8081
Click to watch the demo :
Youtube demo video :
Case 2 Quotes replace
sometimes your config file needs string quotes, (like for env vars or connection string):
namespace="production"
template file example :
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: {{namespace}}
spec:
ports:
- targetPort: 80
name: nginxhttp
port: {{exposePort}}
let's say we need a quote in the namespace :
crab -f inputfile.yaml -q namespace=production -r exposePort=8081 -o result.yaml -v
yass you can simultaneously Replace multiple key values with quotes or not ✔️
result will be :
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: "production"
spec:
ports:
- targetPort: 80
name: nginxhttp
port: 8081
Related article
- Replacing kubernetes manifest value dynamicly (coming soon on medium)