Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pawelchcki/cdk8s-bazel
https://github.com/pawelchcki/cdk8s-bazel
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pawelchcki/cdk8s-bazel
- Owner: pawelchcki
- License: apache-2.0
- Created: 2021-06-13T17:36:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-25T10:03:20.000Z (over 3 years ago)
- Last Synced: 2024-04-18T04:11:48.310Z (8 months ago)
- Language: Python
- Size: 464 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Bazel wrapper for cdk8s
This bazel repository contains simple wrappers around [cdk8s](https://github.com/cdk8s-team/cdk8s) Python library.
It allows building Kubernetes configuration using Python objects, which might be prefferable over templating
yaml using text templating language.## Usage
See: examples folder### WORKSPACE
```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")http_archive(
name = "bazel_cdk8s",
urls = ["https://github.com/pawelchcki/cdk8s-bazel/releases/download/0.2.0/cdk8s-bazel-0.2.0.tar.gz"],
sha256 = "5731046ee90da48cb484f7cff685286f3327d321365485f30540bb61b03aed91",
)load("@bazel_cdk8s//deps:python.bzl", "cdk8s_rules_python")
cdk8s_rules_python()
load("@bazel_cdk8s//:deps.bzl", "cdk8s_init")
cdk8s_init()
```### BUILD
```python
load("@bazel_cdk8s//:rules.bzl", "cdk8s_yaml")cdk8s_yaml(name="simple", main = "simple.py")
```### simple.py
```python
#!/usr/bin/env python
from constructs import Construct, MetadataEntry
from cdk8s import App, Chart
from cdk8s_py.api import k8sclass MyChart(Chart):
def __init__(self, scope: Construct, id: str):
super().__init__(scope, id)label = {"app": id}
hello_kubernetes = k8s.Container(
name='hello-kubernetes',
image='paulbouwer/hello-kubernetes:1.7',
ports=[k8s.ContainerPort(container_port=8080)]
)k8s.KubeStatefulSet(self, 'app-set',
spec=k8s.StatefulSetSpec(
replicas=1,
service_name=id,
selector=k8s.LabelSelector(match_labels=label),
template=k8s.PodTemplateSpec(
metadata=k8s.ObjectMeta(labels=label),
spec=k8s.PodSpec(
containers=[hello_kubernetes]))))app = App()
MyChart(app, "sample")
app.synth()
```### Output:
```yaml
# $ bazel build :simple.yaml
# $ cat bazel-bin/sample.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: sample-app-set-c8800f2b
spec:
replicas: 1
selector:
matchLabels:
app: sample
serviceName: sample
template:
metadata:
labels:
app: sample
spec:
containers:
- image: paulbouwer/hello-kubernetes:1.7
name: hello-kubernetes
ports:
- containerPort: 8080
```