Skip to content

Instantly share code, notes, and snippets.

@cppforlife
Last active December 16, 2019 15:55
Show Gist options
  • Save cppforlife/f0016812ef398a6c6a22164c90999ce7 to your computer and use it in GitHub Desktop.
Save cppforlife/f0016812ef398a6c6a22164c90999ce7 to your computer and use it in GitHub Desktop.
example of k8s app generated with help of k8s-lib (https://github.com/k14s/k8s-lib)
$ mkdir my-app && cd my-app
$ git clone https://github.com/k14s/k8s-lib _ytt_lib/github.com/k14s/k8s-lib
$ # create `config.yml` with below contents
$ ytt version
Version: 0.23.0 # <-- must be 0.23.0+
$ ytt -f .
$ ytt -f . | kapp deploy -a my-app -f- -y
#@ load("@ytt:template", "template")
#@ load("@ytt:library", "library")
#@ def config(port=80):
name: hello
port: #@ port
#@overlay/replace
container:
image: hashicorp/http-echo
args:
- #@ "-listen=:" + str(port)
- -text="hello!"
#@ end
#@ app = library.get("github.com/k14s/k8s-lib/app").with_data_values(config())
--- #@ template.replace(app.eval())
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
labels:
app.k8s-lib.k14s.io/name: hello
namespace: default
spec:
selector:
matchLabels:
app.k8s-lib.k14s.io/deployment-name: hello
replicas: 1
template:
metadata:
labels:
app.k8s-lib.k14s.io/deployment-name: hello
spec:
containers:
- name: default
ports:
- containerPort: 80
image: hashicorp/http-echo
args:
- -listen=:80
- -text="hello!"
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.k8s-lib.k14s.io/deployment-name
operator: In
values:
- hello
topologyKey: kubernetes.io/hostname
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: hello-hpa
labels:
app.k8s-lib.k14s.io/name: hello
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: hello
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50
---
apiVersion: kapp.k14s.io/v1alpha1
kind: Config
rebaseRules:
- path:
- spec
- replicas
type: copy
sources:
- existing
resourceMatchers:
- kindNamespaceNameMatcher:
kind: Deployment
namespace: default
name: hello
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-ingress
labels:
app.k8s-lib.k14s.io/name: hello
namespace: default
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: hello-service
servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
name: hello-service
labels:
app.k8s-lib.k14s.io/name: hello
namespace: default
spec:
ports:
- port: 80
protocol: TCP
selector:
app.k8s-lib.k14s.io/deployment-name: hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment