diff --git a/kas/Pluralfile b/kas/Pluralfile new file mode 100644 index 000000000..57f7974ee --- /dev/null +++ b/kas/Pluralfile @@ -0,0 +1,6 @@ +REPO kas +ATTRIBUTES Plural repository.yaml + +TF terraform/* +HELM helm/* +RECIPE plural/recipes/* diff --git a/kas/helm/kas/.helmignore b/kas/helm/kas/.helmignore new file mode 100644 index 000000000..691fa13d6 --- /dev/null +++ b/kas/helm/kas/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ \ No newline at end of file diff --git a/kas/helm/kas/Chart.yaml b/kas/helm/kas/Chart.yaml new file mode 100644 index 000000000..71eb703ca --- /dev/null +++ b/kas/helm/kas/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +name: kas +description: k8s agent server +type: application +version: 0.0.0 +appVersion: "0.0.0" diff --git a/kas/helm/kas/deps.yaml b/kas/helm/kas/deps.yaml new file mode 100644 index 000000000..db1e696a6 --- /dev/null +++ b/kas/helm/kas/deps.yaml @@ -0,0 +1,15 @@ +apiVersion: plural.sh/v1alpha1 +kind: Dependencies +metadata: + application: true + description: Deploys kas crafted for the target cloud +spec: + dependencies: + - type: helm + name: bootstrap + repo: bootstrap + version: '>= 0.5.1' + - type: terraform + name: kube + repo: kas + version: '>= 0.1.0' diff --git a/kas/helm/kas/templates/_helpers.tpl b/kas/helm/kas/templates/_helpers.tpl new file mode 100644 index 000000000..3fd69cf22 --- /dev/null +++ b/kas/helm/kas/templates/_helpers.tpl @@ -0,0 +1,76 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "kas.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "kas.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "kas.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "kas.labels" -}} +helm.sh/chart: {{ include "kas.chart" . }} +{{ include "kas.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "kas.selectorLabels" -}} +app.kubernetes.io/name: {{ include "kas.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service to use +*/}} +{{- define "kas.serviceName" -}} +{{- printf "%s-service" (include "kas.fullname" .) }} +{{- end }} + +{{/* +Create the name of the config map to use +*/}} +{{- define "kas.configMapName" -}} +{{- printf "%s-config" (include "kas.fullname" .) }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "kas.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "kas.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/kas/helm/kas/templates/configmap.yaml b/kas/helm/kas/templates/configmap.yaml new file mode 100644 index 000000000..9320e66ba --- /dev/null +++ b/kas/helm/kas/templates/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "kas.configMapName" . }} + labels: + {{- include "kas.labels" . | nindent 4 }} +data: + config.yaml: | + plural_url: "" # TODO: Add full config. diff --git a/kas/helm/kas/templates/deployment.yaml b/kas/helm/kas/templates/deployment.yaml new file mode 100644 index 000000000..54e3e289c --- /dev/null +++ b/kas/helm/kas/templates/deployment.yaml @@ -0,0 +1,99 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "kas.fullname" . }} + labels: + {{- include "kas.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "kas.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + cluster-autoscaler.kubernetes.io/safe-to-evict: "true" + {{- if and .Values.metrics.enabled (not .Values.metrics.serviceMonitor.enabled) }} + prometheus.io/scrape: "true" + prometheus.io/port: {{ .Values.observability.port | quote }} + prometheus.io/path: {{ .Values.metrics.path }} + {{- end }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "kas.selectorLabels" . | nindent 8 }} + spec: + automountServiceAccountToken: false + {{- with .Values.image.pullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- with .Values.priorityClassName }} + priorityClassName: {{ . }} + {{- end }} + serviceAccountName: {{ include "kas.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }} + image: {{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + args: + - "--configuration-file=/etc/kas/config.yaml" + {{- range .Values.extraArgs }} + - {{ . }} + {{- end }} + env: + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + {{- if .Values.extraEnv }} + {{- toYaml .Values.extraEnv | nindent 12 }} + {{- end }} + ports: + - containerPort: {{ .Values.service.internalPort }} + - containerPort: {{ .Values.service.kubernetesApiPort }} + - containerPort: {{ .Values.service.privateApiPort }} + - containerPort: {{ .Values.service.observabilityPort }} + readinessProbe: + httpGet: + path: /readiness + port: {{ .Values.service.observabilityPort }} + initialDelaySeconds: 5 + periodSeconds: 10 + livenessProbe: + httpGet: + path: /liveness + port: {{ .Values.service.observabilityPort }} + initialDelaySeconds: 15 + periodSeconds: 20 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: etc-kas + mountPath: /etc/kas + readOnly: true + terminationGracePeriodSeconds: 300 + volumes: + - name: etc-kas + projected: + defaultMode: 0440 + sources: + - configMap: + name: {{ template "kas.configMapName" . }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} \ No newline at end of file diff --git a/kas/helm/kas/templates/hpa.yaml b/kas/helm/kas/templates/hpa.yaml new file mode 100644 index 000000000..b0fd0911a --- /dev/null +++ b/kas/helm/kas/templates/hpa.yaml @@ -0,0 +1,40 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "kas.fullname" . }} + labels: + {{- include "kas.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "kas.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUAverageValue }} + - type: Resource + resource: + name: cpu + target: + type: AverageValue + averageValue: {{ .Values.autoscaling.targetCPUAverageValue }} + {{- end }} + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/kas/helm/kas/templates/serviceaccount.yaml b/kas/helm/kas/templates/serviceaccount.yaml new file mode 100644 index 000000000..b0bf3c3c0 --- /dev/null +++ b/kas/helm/kas/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "kas.serviceAccountName" . }} + labels: + {{- include "kas.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/kas/helm/kas/templates/servicemonitor.yaml b/kas/helm/kas/templates/servicemonitor.yaml new file mode 100644 index 000000000..cc8c15705 --- /dev/null +++ b/kas/helm/kas/templates/servicemonitor.yaml @@ -0,0 +1,25 @@ +{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "kas.serviceName" . }} + labels: + {{- include "kas.labels" . | nindent 4 }} + {{- with .Values.metrics.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + namespaceSelector: + matchNames: + - {{ $.Release.Namespace }} + selector: + matchLabels: + app: {{ template "kas.name" . }} + release: {{ .Release.Name }} + endpoints: + - port: http-metrics + path: {{ .Values.metrics.path }} + {{- with .Values.metrics.serviceMonitor.endpointConfig }} + {{- toYaml . | nindent 6 }} + {{- end }} +{{- end -}} diff --git a/kas/helm/kas/values.yaml b/kas/helm/kas/values.yaml new file mode 100644 index 000000000..f0b86db12 --- /dev/null +++ b/kas/helm/kas/values.yaml @@ -0,0 +1,75 @@ +image: + # See: https://github.com/pluralsh/kubernetes-agent/pkgs/container/kas. + repository: ghcr.io/pluralsh/kas + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + pullSecrets: [] + +nameOverride: "" + +fullnameOverride: "" + +podAnnotations: {} + +podSecurityContext: + runAsUser: 65532 + +securityContext: + runAsUser: 65532 + runAsGroup: 65532 + fsGroup: 65532 + +priorityClassName: "" + +extraEnv: [] + +extraArgs: [] + +nodeSelector: {} + +affinity: {} + +tolerations: [] + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + +service: + externalPort: 8150 + internalPort: 8150 + apiInternalPort: 8153 + kubernetesApiPort: 8154 + privateApiPort: 8155 + observabilityPort: 8151 + type: ClusterIP + +serviceAccount: + # Specifies whether a service account should be created. + create: true + # Annotations to add to the service account. + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template. + name: "" + +metrics: + enabled: true + path: /metrics + serviceMonitor: + enabled: false + additionalLabels: {} + endpointConfig: {} + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 10 + targetCPUAverageValue: 100m + # targetCPUUtilizationPercentage: 75 + # targetMemoryUtilizationPercentage: 75 diff --git a/kas/helm/kas/values.yaml.tpl b/kas/helm/kas/values.yaml.tpl new file mode 100644 index 000000000..e69de29bb diff --git a/kas/plural/icons/kas.png b/kas/plural/icons/kas.png new file mode 100644 index 000000000..5f0f3b04b Binary files /dev/null and b/kas/plural/icons/kas.png differ diff --git a/kas/plural/notes.tpl b/kas/plural/notes.tpl new file mode 100644 index 000000000..1bdcf8a3c --- /dev/null +++ b/kas/plural/notes.tpl @@ -0,0 +1 @@ +Use `plural watch kas` to track the status of your application \ No newline at end of file diff --git a/kas/plural/recipes/terraria-aws.yaml b/kas/plural/recipes/terraria-aws.yaml new file mode 100644 index 000000000..9cad59de4 --- /dev/null +++ b/kas/plural/recipes/terraria-aws.yaml @@ -0,0 +1,18 @@ +name: kas-aws +description: Installs kas +provider: AWS +primary: true +dependencies: +- repo: bootstrap + name: aws-k8s +sections: +- name: kas + configuration: + - name: hostname + documentation: domain on which you'd like to host kas + type: DOMAIN + items: + - type: TERRAFORM + name: kube + - type: HELM + name: kas diff --git a/kas/plural/recipes/terraria-azure.yaml b/kas/plural/recipes/terraria-azure.yaml new file mode 100644 index 000000000..6933cd05f --- /dev/null +++ b/kas/plural/recipes/terraria-azure.yaml @@ -0,0 +1,18 @@ +name: kas-azure +description: Installs kas +provider: AZURE +primary: true +dependencies: +- repo: bootstrap + name: azure-k8s +sections: +- name: kas + configuration: + - name: hostname + documentation: domain on which you'd like to host kas + type: DOMAIN + items: + - type: TERRAFORM + name: kube + - type: HELM + name: kas diff --git a/kas/plural/recipes/terraria-gcp.yaml b/kas/plural/recipes/terraria-gcp.yaml new file mode 100644 index 000000000..70f2fb0a7 --- /dev/null +++ b/kas/plural/recipes/terraria-gcp.yaml @@ -0,0 +1,18 @@ +name: kas-gcp +description: Installs kas +provider: GCP +primary: true +dependencies: +- repo: bootstrap + name: gcp-k8s +sections: +- name: kas + configuration: + - name: hostname + documentation: domain on which you'd like to host kas + type: DOMAIN + items: + - type: TERRAFORM + name: kube + - type: HELM + name: kas diff --git a/kas/repository.yaml b/kas/repository.yaml new file mode 100644 index 000000000..7651cc499 --- /dev/null +++ b/kas/repository.yaml @@ -0,0 +1,7 @@ +name: kas +description: kas deployed on Kubernetes +category: PRODUCTIVITY +private: true +icon: plural/icons/kas.png +darkIcon: plural/icons/kas.png +notes: plural/notes.tpl diff --git a/kas/terraform/kube/deps.yaml b/kas/terraform/kube/deps.yaml new file mode 100644 index 000000000..70a6e4ce9 --- /dev/null +++ b/kas/terraform/kube/deps.yaml @@ -0,0 +1,26 @@ +apiVersion: plural.sh/v1alpha1 +kind: Dependencies +metadata: + description: kas k8s setup + version: 0.1.0 +spec: + dependencies: + - name: aws-bootstrap + repo: bootstrap + type: terraform + version: '>= 0.1.1' + optional: true + - name: azure-bootstrap + repo: bootstrap + type: terraform + version: '>= 0.1.1' + optional: true + - name: gcp-bootstrap + repo: bootstrap + type: terraform + version: '>= 0.1.1' + optional: true + providers: + - aws + - azure + - gcp diff --git a/kas/terraform/kube/main.tf b/kas/terraform/kube/main.tf new file mode 100644 index 000000000..4844e269c --- /dev/null +++ b/kas/terraform/kube/main.tf @@ -0,0 +1,10 @@ +resource "kubernetes_namespace" "kas" { + metadata { + name = var.namespace + labels = { + "app.kubernetes.io/managed-by" = "plural" + "app.plural.sh/name" = "kas" + } + } +} + diff --git a/kas/terraform/kube/terraform.tfvars b/kas/terraform/kube/terraform.tfvars new file mode 100644 index 000000000..961103ecf --- /dev/null +++ b/kas/terraform/kube/terraform.tfvars @@ -0,0 +1,2 @@ +namespace = {{ .Namespace | quote }} +cluster_name = {{ .Cluster | quote }} \ No newline at end of file diff --git a/kas/terraform/kube/variables.tf b/kas/terraform/kube/variables.tf new file mode 100644 index 000000000..a596100ab --- /dev/null +++ b/kas/terraform/kube/variables.tf @@ -0,0 +1,8 @@ +variable "namespace" { + type = string + default = "kas" +} + +variable "cluster_name" { + type = string +} diff --git a/kas/vendor_images.yaml b/kas/vendor_images.yaml new file mode 100644 index 000000000..e69de29bb