README
¶
provisioner
This directory contains the provisioner package. On a high level the provisioner's main responsibility is to allocate resources on a runtime to a deployment. Currently there is two different types of provisioners, static
and kubernetes
. The static
type will allocate a runtime from a statically pre-defined pool of runtimes and the kubernetes
type will dynamically provision a dedicated runtime in Kubernetes and allocate it to the deployment.
Configuration
The provisioner is configured using RILL_ADMIN_PROVISIONER_SET_JSON
with a named set of provisioners using a format like the following example. More provisioners of the same type can be configured, this is a useful for example to support deployments to different Kubernetes clusters. Furthermore the name of the default provisioner needs to be specified with RILL_ADMIN_DEFAULT_PROVISIONER
, this provisioner will be used for all deployed projects where a provisioner is not explicitly chosen.
{
"static-example":
{
"type": "static",
"spec":
{
"runtimes":
[
{
"host": "http://localhost:9091", // Runtime host
"slots": 50, // Amount of slots in the pre-provisioned runtime
"data_dir": "/mnt/data", // Directory to use for data storage like DB files etc.
"audience_url": "http://localhost:8081" // Audience URL (JWT)
}
]
}
},
"kubernetes-example":
{
"type": "kubernetes",
"spec":
{
"timeout_seconds": 30, // Maximum time to wait for the runtime to become ready
"data_dir": "/mnt/data", // Directory to use for data storage like DB files etc.
"host": "http://node-*.localhost", // The wildcard '*' will be replaced with the deployment's 'provision_id'
"namespace": "cloud-runtime", // Namespace to use in the K8s cluster
"image": "rilldata/rill", // Rill Docker image
"kubeconfig_path": "kubeconfig.yaml", // K8s config file to authenticate against the cluster
"template_paths":
{
"http_ingress": "templates/http_ingress.yaml", // Ingress resource template for HTTP
"grpc_ingress": "templates/grpc_ingress.yaml", // Ingress resource template for GRCP
"service": "templates/service.yaml", // Service resource template
"deployment": "templates/deployment.yaml", // Deployment resource template
"pvc": "templates/pvc.yaml" // PVC resource template
}
}
}
}
Development
Be aware that the runtimes provisioned in Kubernetes will need to be able to communicate with the admin server to function correctly, so if the admin server is running locally and you setup provisioning to an external cluster, you'll need to make sure there's an available network path from the runtimes to your local admin server.
Templates
The Kubernetes resource templates provides a high level of flexibility, but they will need to be adapted to the specific Kubernetes environment. The simplified examples below will provide a good starting point.
Note: For internal Rill users refer to our private infra repos containing environment specific configurations and templates.
deployment.yaml
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: {{ .Names.Deployment }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ .Names.Deployment }}
spec:
securityContext:
fsGroup: 1000
volumes:
- name: data
persistentVolumeClaim:
claimName: {{ .Names.PVC }}
containers:
- args:
- runtime
- start
command:
- rill
env:
- name: RILL_RUNTIME_GRPC_PORT
value: "9090"
- name: RILL_RUNTIME_HTTP_PORT
value: "8080"
########################################################################
# Add all the relevant runtime configuration environment variables here
########################################################################
image: "{{ .Image }}:{{ .ImageTag }}"
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
httpGet:
path: /v1/ping
port: 8080
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
name: cloud-runtime
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 9090
protocol: TCP
resources:
limits:
cpu: {{ .CPU }}
memory: {{ .MemoryGB }}Gi
requests:
cpu: {{ .CPU }}
memory: {{ .MemoryGB }}Gi
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_BIND_SERVICE
drop:
- all
runAsNonRoot: true
runAsUser: 1000
terminationMessagePolicy: FallbackToLogsOnError
volumeMounts:
- mountPath: {{ .DataDir }}
name: data
service.yaml
apiVersion: v1
kind: Service
spec:
type: ClusterIP
ports:
- name: http
port: 8080
targetPort: 8080
- name: grpc
port: 9090
targetPort: 9090
selector:
app.kubernetes.io/name: {{ .Names.Deployment }}
grpc_ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/backend-protocol: GRPC
spec:
ingressClassName: nginx
rules:
- host: {{ .Host }}
http:
paths:
- backend:
service:
name: {{ .Names.Service }}
port:
number: 9090
path: /
pathType: Prefix
http_ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
spec:
ingressClassName: nginx
rules:
- host: {{ .Host }}
http:
paths:
- backend:
service:
name: {{ .Names.Service }}
port:
number: 8080
path: /v1
pathType: Prefix
pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .StorageBytes }}
storageClassName: storageclass-example
Documentation
¶
Index ¶
- func NewSet(set string, db database.DB, logger *zap.Logger) (map[string]Provisioner, error)
- type Allocation
- type KubernetesProvisioner
- func (p *KubernetesProvisioner) AwaitReady(ctx context.Context, provisionID string) error
- func (p *KubernetesProvisioner) CheckCapacity(ctx context.Context) error
- func (p *KubernetesProvisioner) Deprovision(ctx context.Context, provisionID string) error
- func (p *KubernetesProvisioner) Provision(ctx context.Context, opts *ProvisionOptions) (*Allocation, error)
- func (p *KubernetesProvisioner) Type() string
- func (p *KubernetesProvisioner) ValidateConfig(ctx context.Context, provisionID string) (bool, error)
- type KubernetesSpec
- type KubernetesTemplatePaths
- type ProvisionOptions
- type Provisioner
- type ProvisionerSpec
- type ResourceNames
- type StaticProvisioner
- func (p *StaticProvisioner) AwaitReady(ctx context.Context, provisionID string) error
- func (p *StaticProvisioner) CheckCapacity(ctx context.Context) error
- func (p *StaticProvisioner) Deprovision(ctx context.Context, provisionID string) error
- func (p *StaticProvisioner) Provision(ctx context.Context, opts *ProvisionOptions) (*Allocation, error)
- func (p *StaticProvisioner) Type() string
- func (p *StaticProvisioner) ValidateConfig(ctx context.Context, provisionID string) (bool, error)
- type StaticRuntimeSpec
- type StaticSpec
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Allocation ¶ added in v0.24.3
type KubernetesProvisioner ¶ added in v0.43.0
type KubernetesProvisioner struct { Spec *KubernetesSpec // contains filtered or unexported fields }
func NewKubernetes ¶ added in v0.43.0
func NewKubernetes(spec json.RawMessage) (*KubernetesProvisioner, error)
func (*KubernetesProvisioner) AwaitReady ¶ added in v0.43.0
func (p *KubernetesProvisioner) AwaitReady(ctx context.Context, provisionID string) error
func (*KubernetesProvisioner) CheckCapacity ¶ added in v0.43.0
func (p *KubernetesProvisioner) CheckCapacity(ctx context.Context) error
func (*KubernetesProvisioner) Deprovision ¶ added in v0.43.0
func (p *KubernetesProvisioner) Deprovision(ctx context.Context, provisionID string) error
func (*KubernetesProvisioner) Provision ¶ added in v0.43.0
func (p *KubernetesProvisioner) Provision(ctx context.Context, opts *ProvisionOptions) (*Allocation, error)
func (*KubernetesProvisioner) Type ¶ added in v0.47.2
func (p *KubernetesProvisioner) Type() string
func (*KubernetesProvisioner) ValidateConfig ¶ added in v0.47.2
type KubernetesSpec ¶ added in v0.43.0
type KubernetesTemplatePaths ¶ added in v0.43.0
type ProvisionOptions ¶
type Provisioner ¶
type Provisioner interface { Provision(ctx context.Context, opts *ProvisionOptions) (*Allocation, error) Deprovision(ctx context.Context, provisionID string) error AwaitReady(ctx context.Context, provisionID string) error CheckCapacity(ctx context.Context) error ValidateConfig(ctx context.Context, provisionID string) (bool, error) Type() string }
type ProvisionerSpec ¶ added in v0.43.0
type ProvisionerSpec struct { Type string `json:"type"` Spec json.RawMessage `json:"spec"` }
type ResourceNames ¶ added in v0.43.0
type StaticProvisioner ¶ added in v0.26.0
type StaticProvisioner struct { Spec *StaticSpec // contains filtered or unexported fields }
func NewStatic ¶
func NewStatic(spec json.RawMessage, db database.DB, logger *zap.Logger) (*StaticProvisioner, error)
func (*StaticProvisioner) AwaitReady ¶ added in v0.43.0
func (p *StaticProvisioner) AwaitReady(ctx context.Context, provisionID string) error
func (*StaticProvisioner) CheckCapacity ¶ added in v0.43.0
func (p *StaticProvisioner) CheckCapacity(ctx context.Context) error
func (*StaticProvisioner) Deprovision ¶ added in v0.43.0
func (p *StaticProvisioner) Deprovision(ctx context.Context, provisionID string) error
func (*StaticProvisioner) Provision ¶ added in v0.26.0
func (p *StaticProvisioner) Provision(ctx context.Context, opts *ProvisionOptions) (*Allocation, error)
func (*StaticProvisioner) Type ¶ added in v0.47.2
func (p *StaticProvisioner) Type() string
func (*StaticProvisioner) ValidateConfig ¶ added in v0.47.2
type StaticRuntimeSpec ¶ added in v0.26.0
type StaticSpec ¶ added in v0.26.0
type StaticSpec struct {
Runtimes []*StaticRuntimeSpec `json:"runtimes"`
}