Kubernetes¶
Overview¶
Very similar to how things are done with terraform configs, we create a context and add kubernetes objects to it:
from p10s import k8s, value
c = k8s.Context()
deployment = k8s.Deployment(yaml("""
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
"""))
deployment.body['metadata']['labels']['env'] = value('ENV')
c += deployment
c += k8s.Service(yaml("""
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
...
"""))
...
While you can always pass in a dict object to the various
KubernetesObject class constructors it’s usually easier, and closer to
what you already know, to use the yaml
helper to parse a bock of
yaml code and start working with that. you can use the
apiVersion
,
metadata
, and
spec
properties no
matter how the object was created.
The various KubernetesObject clsses exist only for readability and
convenience, creating a base KubernetesObject and passing in kind
is the fully equivalent. This is also the way to create ojects for
kinds that are not pre-defined.
p10s takes advantage of the fact that you can have multiple kubernetes
objects in the same yaml file (represented as multiple kubernetes
documents). Multiple KubernetesObject
objects can be added to the
same k8s.Context
, in the same p10s script, and kubernetes and helm
will be able to properly parse it.
Objects¶
Helpers¶
Base Classes¶
- class p10s.kubernetes.Context(*args, data=None, **kwargs)[source]¶
Context class for generating kubernetes and helm files.
Really is just a YAML context.
- class p10s.kubernetes.KubernetesObject(data=None, kind=None)[source]¶
- property apiVersion¶
Property mapping this object’s
apiVersion
value
- property kind¶
Property mapping this object’s
kind
value
- property metadata¶
Property mapping this object’s
metadata
value
- property spec¶
Property mapping this object’s
spec
value