Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package-examples/ghost/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: ghost
annotations:
config.kubernetes.io/local-config: "true"
info:
description: sample description
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-namespace:v0.3.4
configPath: package-context.yaml
32 changes: 32 additions & 0 deletions package-examples/ghost/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Ghost Application

"Ghost is a powerful app for new-media creators to publish, share, and grow a business around their content. It comes with modern tools to build a website, publish content, send newsletters & offer paid subscriptions to members."
https://ghost.org/

### Quick start

#### Get KPT Pacakge
```bash
export NAMESPACE=<YOUR NAMESPACE>
# make sure the namespace is correct and exists. Otherwise, create the namespace
kubectl create namespace ${NAMESPACE}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we add namespace to the package itself ?

If you used helm chart to get the manifests, you can use --create-namespace arg to add it.

That will make the workflow truly declarative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability to create a namespace would imply that the app team had cluster admin privilege. It also would bring in the need for the flexibility of the namespace provisioning scenario we've been working on: resource quota, limit range, network policy, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have an example namespace blueprint for this, which could be used instead of kubectl create namespace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability to create a namespace would imply that the app team had cluster admin privilege. It also would bring in the need for the flexibility of the namespace provisioning scenario we've been working on: resource quota, limit range, network policy, etc.

Aah.. completely missed that. Good pt.


# You get this Ghost package by running
kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/ghost@main ${NAMESPACE} --for-deployment
```

#### Update the KRM resources to your own data

Updating the KRM resources are easy with variant constructor
```bash
kpt fn render ${NAMESPACE}
```

#### Deploy the KRM resources to your cluster

```bash
# Initialize inventory info. You only need to run this if do not have resourcesgroup.yaml
kpt live init ${NAMESPACE}

kpt live apply ${NAMESPACE}
```
102 changes: 102 additions & 0 deletions package-examples/ghost/crds/prometheusrules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: prometheusrules.monitoring.coreos.com
spec:
group: monitoring.coreos.com
names:
categories:
- prometheus-operator
kind: PrometheusRule
listKind: PrometheusRuleList
plural: prometheusrules
shortNames:
- promrule
singular: prometheusrule
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: PrometheusRule defines recording and alerting rules for a Prometheus
instance
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Specification of desired alerting rule definitions for Prometheus.
properties:
groups:
description: Content of Prometheus rule file
items:
description: 'RuleGroup is a list of sequentially evaluated recording
and alerting rules. Note: PartialResponseStrategy is only used
by ThanosRuler and will be ignored by Prometheus instances. Valid
values for this field are ''warn'' or ''abort''. More info: https://github.com/thanos-io/thanos/blob/main/docs/components/rule.md#partial-response'
properties:
interval:
type: string
name:
type: string
partial_response_strategy:
type: string
rules:
items:
description: 'Rule describes an alerting or recording rule
See Prometheus documentation: [alerting](https://www.prometheus.io/docs/prometheus/latest/configuration/alerting_rules/)
or [recording](https://www.prometheus.io/docs/prometheus/latest/configuration/recording_rules/#recording-rules)
rule'
properties:
alert:
type: string
annotations:
additionalProperties:
type: string
type: object
expr:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
for:
type: string
labels:
additionalProperties:
type: string
type: object
record:
type: string
required:
- expr
type: object
type: array
required:
- name
- rules
type: object
type: array
type: object
required:
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
8 changes: 8 additions & 0 deletions package-examples/ghost/ghost-app/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: ghost-app
annotations:
config.kubernetes.io/local-config: "true"
info:
description: The Ghost App package contains the KRM resources for a Ghost Application.
95 changes: 95 additions & 0 deletions package-examples/ghost/ghost-app/deployment-ghost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ghost-app
namespace: example
spec:
replicas: 1
strategy:
type: RollingUpdate
template:
spec:
affinity:
podAffinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
namespaces:
- "example"
topologyKey: kubernetes.io/hostname
weight: 1
nodeAffinity:
securityContext:
fsGroup: 1001
containers:
- name: ghost-app
image: docker.io/bitnami/ghost:4.45.0-debian-10-r0
imagePullPolicy: "IfNotPresent"
securityContext:
runAsNonRoot: true
runAsUser: 1001
env:
- name: BITNAMI_DEBUG
value: "false"
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
- name: GHOST_DATABASE_HOST
value: "example-mariadb"
- name: GHOST_DATABASE_PORT_NUMBER
value: "3306"
- name: GHOST_DATABASE_NAME
value: "bitnami_ghost"
- name: GHOST_DATABASE_USER
value: "bn_ghost"
- name: GHOST_HOST
value: "aa/"
- name: GHOST_PORT_NUMBER
value: "2368"
- name: GHOST_USERNAME
value: "user"
- name: GHOST_EMAIL
value: "[email protected]"
- name: GHOST_BLOG_TITLE
value: "User's Blog"
- name: GHOST_ENABLE_HTTPS
value: "no"
- name: GHOST_EXTERNAL_HTTP_PORT_NUMBER
value: "80"
- name: GHOST_EXTERNAL_HTTPS_PORT_NUMBER
value: "443"
- name: GHOST_SKIP_BOOTSTRAP
value: "no"
ports:
- name: http
containerPort: 2368
protocol: TCP
livenessProbe:
httpGet:
path: /
port: "http"
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
httpGet:
path: /
port: "http"
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 6
successThreshold: 1
resources:
limits: {}
requests: {}
volumeMounts:
- name: ghost-data
mountPath: /bitnami/ghost
volumes:
- name: ghost-data
persistentVolumeClaim:
claimName: ghost-app
17 changes: 17 additions & 0 deletions package-examples/ghost/ghost-app/ingress-ghost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ghost-app
namespace: example
spec:
rules:
- host: ghost.local
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: ghost-app
port:
name: http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: ghost-app
spec:
ingress:
8 changes: 8 additions & 0 deletions package-examples/ghost/ghost-app/package-context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kptfile.kpt.dev
annotations:
config.kubernetes.io/local-config: "true"
data:
name: example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Source: ghost/templates/pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ghost-app
namespace: example
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "8Gi"
14 changes: 14 additions & 0 deletions package-examples/ghost/ghost-app/service-ghost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: ghost-app
namespace: example
spec:
type: LoadBalancer
externalTrafficPolicy: Cluster
sessionAffinity: None
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
8 changes: 8 additions & 0 deletions package-examples/ghost/mariadb/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: mariadb
annotations:
config.kubernetes.io/local-config: "true"
info:
description: The MariaDB which provides the storage for Ghost.
36 changes: 36 additions & 0 deletions package-examples/ghost/mariadb/configmap-mariadb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Source: ghost/charts/mariadb/templates/primary/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mariadb
namespace: example
data:
my.ini: |-
[mysqld]
skip-name-resolve
explicit_defaults_for_timestamp
basedir=/opt/bitnami/mariadb
plugin_dir=/opt/bitnami/mariadb/plugin
port=3306
socket=/opt/bitnami/mariadb/tmp/mysql.sock
tmpdir=/opt/bitnami/mariadb/tmp
max_allowed_packet=16M
bind-address=*
pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
log-error=/opt/bitnami/mariadb/logs/mysqld.log
character-set-server=UTF8
collation-server=utf8_general_ci
slow_query_log=0
slow_query_log_file=/opt/bitnami/mariadb/logs/mysqld.log
long_query_time=10.0

[client]
port=3306
socket=/opt/bitnami/mariadb/tmp/mysql.sock
default-character-set=UTF8
plugin_dir=/opt/bitnami/mariadb/plugin

[manager]
port=3306
socket=/opt/bitnami/mariadb/tmp/mysql.sock
pid-file=/opt/bitnami/mariadb/tmp/mysqld.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Source: ghost/charts/mariadb/templates/primary/networkpolicy-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: mariadb
spec:
ingress:
8 changes: 8 additions & 0 deletions package-examples/ghost/mariadb/package-context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kptfile.kpt.dev
annotations:
config.kubernetes.io/local-config: "true"
data:
name: example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so variant constructor pattern isn't support well (or tested :)) for nested packages, so will be interesting to see how this plays out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user in slack has encountered similar issues using Config Connector subpackages (e.g., CloudSQL).

10 changes: 10 additions & 0 deletions package-examples/ghost/mariadb/prometheusrule-mariadb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Source: ghost/charts/mariadb/templates/prometheusrules.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: mariadb
namespace: example
spec:
groups:
- name: mariadb
rules: []
Loading