Apply Apply
Apply Certified

Apply Kubernetes resources with server-side apply

yaml
type: io.kestra.plugin.kubernetes.kubectl.Apply
yaml
id: create_or_replace_deployment
namespace: company.team

tasks:
  - id: apply
    type: io.kestra.plugin.kubernetes.kubectl.Apply
    connection:
      masterUrl: "{{ secret('K8S_MASTER_URL') }}"
      oauthToken: "{{ secret('K8S_TOKEN') }}"
    namespace: default
    spec: |-
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: mypod
        labels:
          app: mypod
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: mypod
        template:
          metadata:
            labels:
              app: mypod
          spec:
            containers:
              - name: app
                image: nginx:stable-alpine
                ports:
                  - containerPort: 80

yaml
id: create_or_replace_deployment
namespace: company.team

tasks:
  - id: apply
    type: io.kestra.plugin.kubernetes.kubectl.Apply
    connection:
      masterUrl: "{{ secret('K8S_MASTER_URL') }}"
      oauthToken: "{{ secret('K8S_TOKEN') }}"
    namespaceFiles:
      enabled: true
    namespace: default
    spec: "{{ read('deployment.yaml') }}"

yaml
id: k8s
namespace: company.name

tasks:
  - id: apply
    type: io.kestra.plugin.kubernetes.kubectl.Apply
    connection:
      masterUrl: "{{ secret('K8S_MASTER_URL') }}"
      oauthToken: "{{ secret('K8S_TOKEN') }}"
    namespace: default
    spec: |-
      apiVersion: apiextensions.k8s.io/v1
      kind: CustomResourceDefinition
      metadata:
        name: shirts.stable.example.com
      spec:
        group: stable.example.com
        scope: Namespaced
        names:
          plural: shirts
          singular: shirt
          kind: Shirt
        versions:
        - name: v1
          served: true
          storage: true
          schema:
            openAPIV3Schema:
              type: object
              properties:
                apiVersion:
                  type: string
                kind:
                  type: string
                metadata:
                  type: object
                spec:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true # Allows any fields in spec
                  properties:
                    # You should define your actual Shirt properties here later
                    # For example:
                    # color:
                    #   type: string
                    # size:
                    #   type: string
                    #   enum: ["S", "M", "L", "XL"]
                status:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true # Allows any fields in status
                  properties:
                    # Define your status properties here
                    # message:
                    #   type: string

yaml
id: apply_and_wait_for_custom_resource
namespace: company.team

tasks:
  - id: apply
    type: io.kestra.plugin.kubernetes.kubectl.Apply
    connection:
      masterUrl: "{{ secret('K8S_MASTER_URL') }}"
      oauthToken: "{{ secret('K8S_TOKEN') }}"
    namespace: default
    waitUntilReady: PT10M
    spec: |-
      apiVersion: example.com/v1
      kind: MyResource
      metadata:
        name: my-resource
      spec:
        foo: bar
Properties
Definitions
apiVersionstring
Defaultv1
caCertDatastring
caCertFilestring
clientCertDatastring
clientCertFilestring
clientKeyAlgostring
DefaultRSA
clientKeyDatastring
clientKeyFilestring
clientKeyPassphrasestring
disableHostnameVerificationbooleanstring
keyStoreFilestring
keyStorePassphrasestring
masterUrlstring
Defaulthttps://kubernetes.default.svc
namespacestring
oauthTokenstring
oauthTokenProvider
outputstring
task
passwordstring
trustCertsbooleanstring
trustStoreFilestring
trustStorePassphrasestring
usernamestring
Default{ "image": "busybox" }
Definitions
defaultSpecobject
imagestring
Defaultbusybox
resourcesobject
SubTypestring
Defaultdefault
SubTypestring
DefaultPT1H
DefaultPT0S
DefaultPT10M
Definitions
annotationsobject
SubTypestring
clusterNamestring
creationTimestampstring
Formatdate-time
deletionGracePeriodSecondsinteger
deletionTimestampstring
Formatdate-time
finalizersarray
SubTypestring
generateNamestring
generationinteger
labelsobject
SubTypestring
managedFieldsarray
apiVersionstring
fieldsTypestring
fieldsV1
managerstring
operationstring
subresourcestring
timestring
namestring
namespacestring
ownerReferencesarray
apiVersionstring
blockOwnerDeletionboolean
controllerboolean
kindstring
namestring
uidstring
resourceVersionstring
selfLinkstring
uidstring

Create automations with Kubernetes Kubectl Apply