Skip to main content
All CollectionsUniskai and Kubernetes
Creating a SchedulePolicy Resource in Kubernetes with Kubesitter
Creating a SchedulePolicy Resource in Kubernetes with Kubesitter
Updated over 3 months ago

In Kubernetes, you can manage resource scheduling for a set of namespaces using the SchedulePolicy custom resource definition (CRD) provided by Kubesitter. This document will guide you through the process of creating a SchedulePolicy resource in your Kubernetes cluster. This allows you to define and manage resource scheduling within specific namespaces, simplifying the management of resource work schedules in your Kubernetes environment.

Prerequisites

Ensure you have the following prerequisites:

  • A running Kubernetes cluster.

  • kubectl command-line tool properly configured for interaction with your cluster.

  • The Uniskai agent installed and properly configured.

Steps to Create a SchedulePolicy Resource

Follow these steps to create a SchedulePolicy resource in your Kubernetes cluster:

  1. Define Your Policy Configuration. You'll need to create a YAML configuration file that defines your policy. Here's an example configuration:

apiVersion: api.profisealabs.com/v1alpha

kind: SchedulePolicy

metadata:

name: example

labels:

purpose: example

spec:

suspend: true

title: "An example policy"

namespaceSelector:

matchNames:

- bookin.*

- emojivoto

timeZone: "Europe/Kyiv"

assignments:

- type: work

from: "2023-09-14T00:00:00"

to: "2023-09-14T22:59:59"

resourceFilter:

matchResources:

- apiVersion: v1

kind: Namespace

name: emojivoto

schedule:

workTimes:

- start: 07:00:00

stop: 18:00:00

days: [Mon, Tue, Wed, Thu, Fri]

- start: 08:00:00

stop: 09:00:00

days: [Sat, Sun]

2. Customize Your Policy Configuration. Customize this configuration to meet your scheduling requirements:

  • apiVersion: Specifies the API version for the custom resource definition (CRD) in use.

  • kind: Defines the type of custom resource being created.

  • metadata: The metadata section for the custom resource, including the resource's name and labels for identification and categorization.

  • spec: The specification section of the custom resource where the policy configuration is defined. The following lines are part of the spec section:

- suspend: A boolean field that suspends the policy when set to true.

- title: A descriptive title or name for the policy.

- namespaceSelector: A section that allows you to select the namespaces (matchLabels, matchExpressions, or matchNames) to which the policy applies. In this example, it uses regular expressions to select namespaces whose names match "bookin.*" and "emojivoto."

- timeZone: Specifies the time zone for the schedule.

- assignments: This section defines the assignments within the policy, which specify the working schedule for specific resources.

- schedule: This section defines the schedule for when resources should be running.

The assignments section includes:

- type: Indicates the type of assignment, which can be "work," "sleep," or "skip."

- from: Specifies the start time of the assignment.

- to: Specifies the end time of the assignment.

- resourceFilter: Allows you to specify an optional filter to select specific resources for the assignment. In this case, it selects the "Namespace" resource with the name "emojivoto." A missing filter means applying assignments to all selected namespaces.

The schedule section includes:

- workTimes: Specifies a list of work times, each representing a time period when resources should be running. Each work time includes:

  • start: Indicates the start time for this work time.

  • stop: Indicates the stop time for this work time.

  • days: Specifies the days of the week when this work time applies.

3. Apply the Configuration. Use the kubectl apply command to apply the configuration to your Kubernetes cluster. Replace <namespace> with the target namespace:

kubectl apply -f your-policy-config.yaml -n <namespace>

This command will create the SchedulePolicy resource with the specified configuration in the target namespace.

4. Verify the Policy. You can verify that the SchedulePolicy has been created by running:

kubectl get SchedulePolicy -n <namespace>

This command will display the details of your newly created SchedulePolicy.

Now, you have successfully created a SchedulePolicy resource in your Kubernetes cluster using Kubesitter. Make sure to adjust the policy configuration to suit your specific needs and requirements. To manage and update your policies, you can modify the configuration in the YAML file and reapply it using kubectl apply.

Did this answer your question?