Skip to main content

72 posts tagged with "KCL"

View All Tags

· 5 min read

KCL is a constraint-based record and functional language hosted by Cloud Native Computing Foundation (CNCF) that enhances the writing of complex configurations, including those for cloud-native scenarios. With its advanced programming language technology and practices, KCL is dedicated to promoting better modularity, scalability, and stability for configurations. It enables simpler logic writing and offers ease of automation APIs and integration with homegrown systems.

This section will update the KCL language community's latest developments every two weeks, including features, website updates, and the latest community news, helping everyone better understand the KCL community!

KCL Website: https://kcl-lang.io

Overview

Thank you to all contributors for their outstanding work over the past two weeks (11.24 - 12.07 2023). Here is an overview of the key content:

📦 Model Updates

KCL model quantity increased to 300, added KCL models for k8s 1.29.

🔧 Toolchain Updates

  • Import Tool Updates

    • Import tool supports OpenAPI allOf keyword validation expression generation
    • Import tool supports KCL array and dictionary type all/any validation expression generation
    • Import tool fixes JSON Schema array generation KCL code snippet error and string escape error
  • 🏄 Package Management Tool Updates

    • Added support for third-party libraries with hyphens in their names.
    • Fixed the problem that the update function cannot automatically pass kcl.mod and kcl.mod.lock.

💻 KCL Updates

  • KCL compilation cache path supports using environment variables KCL_CACHE_PATH to specify
  • Fixed the compilation error that may be caused by the compilation parameter -S of KCL CLI
  • Fixed the error that kcl fmt tool adds an empty line at the end when formatting lambda expressions.
  • Fixed Schema Doc completion code snippet error

📒 IDE Updates

  • Fixed the problem that the variable completion in the check statement is invalid
  • VSCode Extension updated to version 0.1.3, updated the highlighting and completion of some keywords
  • Added completion of builtin functions
  • Optimized the style of function completion

Efficient Cloud Native Application Deployment - KCL and KubeVela Integration Quick Guide

KCL is a configuration and policy language for cloud-native scenarios, hosted by the CNCF Foundation. It aims to improve the writing of complex configurations, such as cloud-native Kubernetes configurations, using mature programming language techniques and practices. KCL focuses on building better modularity, scalability, and stability around configuration, as well as easier logic writing, automation, and integration with the toolchain.

KCL exists in a completely open cloud-native world and is not tied to any orchestration/engine tools or Kubernetes controllers. It can provide API abstraction, composition, and validation capabilities for both Kubernetes clients and runtime.

KubeVela is a modern application delivery system hosted by the CNCF Foundation. It is built on the Open Application Model (OAM) specification and aims to abstract the complexity of Kubernetes, providing a set of simple and easy-to-use command-line tools and APIs for developers to deploy and operate cloud-native applications without worrying about the underlying details.

Using KCL with KubeVela has the following benefits:

  • Simpler configuration: KCL provides stronger templating capabilities, such as conditions and loops, for KubeVela OAM configurations at the client level, reducing the need for repetitive YAML writing. At the same time, the reuse of KCL model libraries and toolchains enhances the experience and management efficiency of configuration and policy writing.
  • Better maintainability: KCL provides a configuration file structure that is more conducive to version control and team collaboration, instead of relying solely on YAML. When combined with OAM application models written in KCL, application configurations become easier to maintain and iterate.
  • Simplified operations: By combining the simplicity of KCL configurations with the ease of use of KubeVela, daily operational tasks such as deploying, updating, scaling, or rolling back applications can be simplified. Developers can focus more on the applications themselves rather than the tedious details of the deployment process.
  • Improved cross-team collaboration: By using KCL's configuration chunk writing and package management capabilities in conjunction with KubeVela, clearer boundaries can be defined, allowing different teams (such as development, testing, and operations teams) to collaborate systematically. Each team can focus on tasks within their scope of responsibility, delivering, sharing, and reusing their own configurations without worrying about other aspects.

Taking the KCL Playground application (written in Go and HTML5) as an example, we use KCL to define the OAM configuration that needs to be deployed. The overall workflow is as follows:

  • Prepare

    • Configure the Kubernetes cluster
    • Install KubeVela
    • Install KCL
  • New project and add OAM dependency

kcl mod init kcl-play-svc && cd kcl-play-svc && kcl mod add oam
  • Write code in main.k
import oam

oam.Application {
metadata.name = "kcl-play-svc"
spec.components = [{
name = metadata.name
type = "webservice"
properties = {
image = "kcllang/kcl:v0.9.0"
ports = [{port = 80, expose = True}]
cmd = ["kcl", "play"]
}
}]
}
  • Run command to deploy configuration
kcl run | vela up -f -
  • Port forwarding
vela port-forward kcl-play-svc

Then we can see the KCL Playground application running successfully in the browser

kcl-play-svc

IDE Optimized the Style of Function Completion

ide-func

Resources

❤️ Thanks to all KCL users and community members for their valuable feedback and suggestions in the community. See here to join us!

For more resources, please refer to

· 4 min read

What is KCL

KCL is an open-source, constraint-based record and functional language that enhances the writing of complex configurations, including those for cloud-native scenarios. It is hosted by the Cloud Native Computing Foundation (CNCF) as a Sandbox Project. With advanced programming language technology and practices, KCL is dedicated to promoting better modularity, scalability, and stability for configurations. It enables simpler logic writing and offers ease of automation APIs and integration with homegrown systems.

Several Ways to Deploy KCL Configuration to a cluster

cloud-native-tool-integration

Since KCL can output YAML/JSON files, theoretically, any method that supports deploying YAML/JSON configurations to a cluster can be used to deploy KCL configurations. Usually, KCL files are stored in Git or Module Registry for easy sharing among different roles and teams. However, KCL can do much more than that, and the main ways to deploy KCL configurations to a cluster are as follows.

  • Using kubectl: The most basic way to access a Kubernetes cluster is using Kubectl. We can directly deploy the Kubernetes YAML configuration files generated by KCL to the cluster using the kubectl apply command. This method is simple and suitable for deploying a small number of resources.
  • Using CI/CD tools: CI/CD tools (such as Jenkins, GitLab CI, CircleCI, ArgoCD, FluxCD, etc.) can be used to achieve GitOps automation deployment of Kubernetes YAML configuration files to the cluster. By defining CI/CD processes and configuration files, automated building and deployment to the cluster can be achieved.
  • Using tools that support KRM Function specification: Kubernetes Resource Model (KRM) Function allows users to use other languages, including KCL, to enhance YAML template and logic writing capabilities, such as writing conditions, loops, etc. These tools mainly include Kustomize, KPT, Crossplane, etc. Although Helm does not natively support KRM Function, we can combine Helm and Kustomize to achieve it.
  • Using client/runtime custom abstract configuration tools for deployment: KusionStack, KubeVela, etc. Of course, KCL allows you to customize your preferred application configuration model.
  • Using KCL Operator with Kubernetes Mutation Webhook and Validation Webhook support for runtime configuration or policy writing.
  • Using configuration management tools: Combine configuration management tools (such as Puppet, Chef, Ansible, etc.) to automate the deployment of Kubernetes YAML configurations to the cluster. These tools can achieve dynamic configuration deployment by defining KCL templates and variables.

The reasons for KCL supporting multiple deployment methods and cloud-native tool integration are as follows:

  • Flexibility: Different deployment methods are suitable for different scenarios and needs, so providing multiple choices allows users to choose the most suitable way to deploy applications or configurations according to their specific situations.
  • Cloud-native tool ecosystem: Kubernetes is a widely used platform with a large ecosystem of tools and technologies. Supporting multiple deployment methods can provide users with more choices to meet their usage habits and technological preferences.
  • Specifications and standards: The Kubernetes community is working to promote standards and specifications, such as OAM, KRM Function specifications, and Helm Charts. By providing multiple support methods through a unified KRM KCL specification and KCL Module, different specification and standard requirements can be met.
  • Automation and integration: Some deployment methods can be integrated through automation tools and CI/CD pipelines to achieve automated deployment processes. Therefore, providing multiple ways can meet different automation and integration needs.

In conclusion, supporting multiple deployment methods can provide users with greater flexibility and choice, allowing them to deploy applications or configurations according to their needs and preferences. The specific usage of each deployment method is as follows:

Using Kubectl

https://kcl-lang.io/blog/2023-11-20-search-k8s-module-on-artifacthub

Using CI/CD Tools

https://kcl-lang.io/blog/2023-07-31-kcl-github-argocd-gitops

Using KRM Function

https://kcl-lang.io/blog/2023-10-23-cloud-native-supply-chain-krm-kcl-spec

Using Custom Abstract Configuration Tools

https://kcl-lang.io/blog/2023-12-15-kubevela-integration

Using KCL Operator

https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator

Using Configuration Management Tools

https://github.com/kcl-lang/kcl/issues/952