Kubernetes CronJobs
Here's an example of how to create a custom scope to implement an EKS CronJob.
For more info
See our article on how to create custom scopes.
1. Create the service
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "EKS CronJob",
"slug": "eks-cron-job",
"type": "scope",
"visible_to": [
"$some-nrn",
"organization=1:account=2:namespace=3"
],
"created_at": "2024-10-29T03:41:54.822Z",
"updated_at": "2024-10-29T03:41:54.822Z",
"attributes": {
"schema": {
"type": "object",
"required": ["cron_expression"],
"properties": {
"asset_type": {
"type": "string",
"export": false,
"default": "docker-image",
"readOnly": true
},
"cron_expression": {
"type": "string",
"export": false,
"readOnly": false
}
}
},
"values": {}
},
"selectors": {
"category": "Deployment Services",
"imported": false,
"provider": "AWS",
"sub_category": "Custom Scope"
}
}'
np service-specification create \
--body '{
"name": "EKS CronJob",
"slug": "eks-cron-job",
"type": "scope",
"visible_to": [
"$some-nrn",
"organization=1:account=2:namespace=3"
],
"created_at": "2024-10-29T03:41:54.822Z",
"updated_at": "2024-10-29T03:41:54.822Z",
"attributes": {
"schema": {
"type": "object",
"required": ["cron_expression"],
"properties": {
"asset_type": {
"type": "string",
"export": false,
"default": "docker-image",
"readOnly": true
},
"cron_expression": {
"type": "string",
"export": false,
"readOnly": false
}
}
},
"values": {}
},
"selectors": {
"category": "Deployment Services",
"imported": false,
"provider": "AWS",
"sub_category": "Custom Scope"
}
}'
Notes:
- This scope accepts
docker-image
assets. - The
cron_expression
parameter is mandatory to set the job's run frequency.
2. Lifecycle actions
Create scope
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Create scope",
"type": "create",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id"],
"properties": {
"scope_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Create scope",
"type": "create",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id"],
"properties": {
"scope_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Start initial
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Start initial",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Start initial",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Start blue green
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Start blue green",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Start blue green",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Finalize blue green
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Finalize blue green",
"type": "finalize",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Finalize blue green",
"type": "finalize",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Rollback deployment
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Rollback deployment",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Rollback deployment",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Delete deployment
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Delete deployment",
"type": "delete",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Delete deployment",
"type": "delete",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id", "deployment_id"],
"properties": {
"scope_id": {
"type": "string"
},
"deployment_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Update scope
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Update scope",
"type": "update",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id"],
"properties": {
"scope_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Update scope",
"type": "update",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id"],
"properties": {
"scope_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
Delete scope
- CLI
- cURL
curl -X POST "https://api.nullplatform.com/service_specification/$service-spec/action_specification" \
-H "Content-Type: application/json" \
-d '{
"name": "Delete scope",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id"],
"properties": {
"scope_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
np service-specification action-specification create \
--serviceSpecificationId $service-spec-id \
--body '{
"name": "Delete scope",
"type": "custom",
"created_at": "2024-08-02T19:32:57.793Z",
"updated_at": "2024-10-01T20:46:48.437Z",
"parameters": {
"schema": {
"type": "object",
"required": ["scope_id"],
"properties": {
"scope_id": {
"type": "string"
}
}
},
"values": {}
},
"results": {
"schema": {
"type": "object",
"properties": {}
},
"values": {}
}
}'
3. Register the custom scope
- CLI
- cURL
np scope-type create
--body '{
"nrn": "organization=1:account=2:namespace=3",
"type": "custom",
"name": "K8S custom",
"status": "active",
"description": "Kubernetes by custom scope",
"provider_type": "service",
"provider_id": "$service-spec-id"
}'
curl -X POST "https://api.nullplatform.com/scope_type" \
-H "Content-Type: application/json" \
-d '{
"nrn": "organization=1:account=2:namespace=3",
"type": "custom",
"name": "K8S custom",
"status": "active",
"description": "Kubernetes by custom scope",
"provider_type": "service",
"provider_id": "$service-spec-id"
}'
4. Implement the actions
You can find an example implementation for an EKS CronJob using GitHub Actions in our repository.