Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Cloud Marketplace
    • Getting started
    • Access management
      • All tutorials
        • Integration with Argo CD
        • Integration with Crossplane
        • Syncing with Yandex Lockbox secrets
        • Configuring Fluent Bit for Cloud Logging
        • Setting up Gateway API
        • Configuring an Application Load Balancer L7 load balancer using an Ingress controller
        • Configuring logging for an Application Load Balancer L7 load balancer using an Ingress controller
        • Creating an L7 load balancer with a Smart Web Security security profile through an Application Load Balancer Ingress controller
        • Health checking your apps in a Managed Service for Kubernetes cluster using an Application Load Balancer L7 load balancer
        • Using Jaeger to trace requests in Managed Service for YDB
        • Setting up Kyverno & Kyverno Policies
        • Using Metrics Provider to stream metrics
        • Editing website images using Thumbor
        • Using Istio
        • Using HashiCorp Vault to store secrets
    • Access management
    • Audit Trails events

In this article:

  • Required paid resources
  • Getting started
  • Install the Kyverno & Kyverno Policies application
  • Check how the policy works for the baseline profile
  • Create and test your own Kyverno policy
  • Test Kyverno & Kyverno Policies
  • Delete the resources you created
  1. Users
  2. Tutorials
  3. Using Cloud Marketplace products in Managed Service for Kubernetes
  4. Setting up Kyverno & Kyverno Policies

Setting up Kyverno & Kyverno Policies

Written by
Yandex Cloud
Updated at May 5, 2025
  • Required paid resources
  • Getting started
  • Install the Kyverno & Kyverno Policies application
  • Check how the policy works for the baseline profile
  • Create and test your own Kyverno policy
  • Test Kyverno & Kyverno Policies
  • Delete the resources you created

The Kyverno application and its Kyverno policies extension are used for managing Kubernetes security policies. They appear in Kyverno as Kubernetes resources.

To integrate Kyverno & Kyverno Policies into Managed Service for Kubernetes:

  1. Install the Kyverno & Kyverno Policies application.
  2. Check how the policy works for the baseline profile.
  3. Create and test your own Kyverno policy.

If you no longer need the resources you created, delete them.

Required paid resourcesRequired paid resources

The support cost includes:

  • Fee for the Managed Service for Kubernetes cluster: using the master and outgoing traffic (see Managed Service for Kubernetes pricing).
  • Cluster nodes (VM) fee: using computing resources, operating system, and storage (see Compute Cloud pricing).
  • Fee for a public IP address assigned to cluster nodes (see Virtual Private Cloud pricing).

Getting startedGetting started

  1. Create a Managed Service for Kubernetes cluster and node group.

    Manually
    Terraform
    1. If you do not have a network yet, create one.

    2. If you do not have any subnets yet, create them in the availability zones where your Kubernetes cluster and node group will be created.

    3. Create security groups for the Managed Service for Kubernetes cluster and its node groups.

      Warning

      The configuration of security groups determines the performance and availability of the cluster and the services and applications running in it.

    4. Create a Managed Service for Kubernetes cluster and a node group in any suitable configuration. When creating them, specify the security groups prepared earlier.

    1. If you do not have Terraform yet, install it.

    2. Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.

    3. Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it.

    4. Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.

    5. Download the k8s-cluster.tf cluster configuration file to the same working directory. This file describes:

      • Network.

      • Subnet.

      • Managed Service for Kubernetes cluster.

      • Service account required for the Managed Service for Kubernetes cluster and node group.

      • Security groups which contain rules required for the Managed Service for Kubernetes cluster and its node groups.

        Warning

        The configuration of security groups determines the performance and availability of the cluster and the services and applications running in it.

    6. Specify the following in the configuration file:

      • Folder ID.
      • Kubernetes version for the Managed Service for Kubernetes cluster and node groups.
      • Kubernetes cluster CIDR.
      • Service account name. It must be unique within the folder.
    7. Make sure the Terraform configuration files are correct using this command:

      terraform validate
      

      If there are any errors in the configuration files, Terraform will point them out.

    8. Create the required infrastructure:

      1. Run this command to view the planned changes:

        terraform plan
        

        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

      2. If everything looks correct, apply the changes:

        1. Run this command:

          terraform apply
          
        2. Confirm updating the resources.

        3. Wait for the operation to complete.

      All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console.

  2. Install kubect and configure it to work with the new cluster.

Install the Kyverno & Kyverno Policies applicationInstall the Kyverno & Kyverno Policies application

Follow this guide to install Kyverno & Kyverno Policies with the following settings:

  • Pod Security Standard profile: baseline.
  • Validation failure action: enforce.

The baseline Pod Security Standard profile already contains a minimum restriction policy that prevents known privilege abuses.

Check how the policy works for the baseline profileCheck how the policy works for the baseline profile

  • Create a pod named nginx with standard parameters:

    kubectl run nginx --image nginx
    

    Result:

    pod/nginx created
    

    Such a pod will satisfy the policy requirements for the baseline profile.

  • Create a pod named nginx in privileged mode:

    kubectl run nginx --image nginx --privileged=true
    

    Result:

    Error from server: admission webhook "validate.kyverno.svc-fail" denied the request:
    
    policy Pod/default/nginx for resource violation:
    
    disallow-privileged-containers:
      privileged-containers: 'validation error: Privileged mode is disallowed. The fields
        spec.containers[*].securityContext.privileged and spec.initContainers[*].securityContext.privileged
        must be unset or set to `false`. rule privileged-containers failed at path /spec/containers/0/securityContext/privileged/'
    

    The policy rules for the baseline profile prohibit creating pods in privileged mode.

Note

Although the policies are designed for pods, Kyverno applies them to any resources able to create pods.

Create and test your own Kyverno policyCreate and test your own Kyverno policy

  1. Create a policy that will require all pods to have the app.kubernetes.io/name label:

    1. Save the ClusterPolicy creation specification to a YAML file named policy.yaml:

      apiVersion: kyverno.io/v1
      kind: ClusterPolicy
      metadata:
        name: require-labels
      spec:
        validationFailureAction: Enforce
        rules:
        - name: check-for-labels
          match:
            any:
            - resources:
                kinds:
                - Pod
          validate:
            message: "label 'app.kubernetes.io/name' is required"
            pattern:
              metadata:
                labels:
                  app.kubernetes.io/name: "?*"
      
    2. Run this command:

      kubectl apply -f policy.yaml
      

      Result:

      clusterpolicy.kyverno.io/require-labels created
      
  2. (Optional) Install Policy Reporter in your Managed Service for Kubernetes cluster to be able to save and process policy results.

Test Kyverno & Kyverno PoliciesTest Kyverno & Kyverno Policies

  • Create a pod named nginx with no app.kubernetes.io/name Kubernetes label:

    kubectl run nginx --image nginx
    

    Result:

    Error from server: admission webhook "validate.kyverno.svc-fail" denied the request:
    resource Pod/default/nginx was blocked due to the following policies
    
    require-labels:
      check-for-labels: 'validation error: label ''app.kubernetes.io/name'' is required.
        Rule check-for-labels failed at path /metadata/labels/app.kubernetes.io/name/'
    
  • Create a pod named nginx with the app.kubernetes.io/name label:

    kubectl run nginx --image nginx --labels app.kubernetes.io/name=nginx
    

    Result:

    pod/nginx created
    

Delete the resources you createdDelete the resources you created

Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need:

Manually
Terraform
  1. Delete the Kubernetes cluster.
  2. Delete the created subnets and networks.
  3. Delete the created service account.
  1. In the terminal window, go to the directory containing the infrastructure plan.

    Warning

    Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.

  2. Delete resources:

    1. Run this command:

      terraform destroy
      
    2. Confirm deleting the resources and wait for the operation to complete.

    All the resources described in the Terraform manifests will be deleted.

Was the article helpful?

Previous
Using Jaeger to trace requests in Managed Service for YDB
Next
Using Metrics Provider to stream metrics
© 2025 Direct Cursus Technology L.L.C.