Use YTT to generate k8s manifests

This commit is contained in:
Chris Cheetham 2021-09-27 11:09:10 -04:00
Родитель c108b7e97d
Коммит 6a879e9124
9 изменённых файлов: 128 добавлений и 44 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -16,3 +16,5 @@
/.project
/.settings/
/bin/
/tools/

Просмотреть файл

@ -24,3 +24,51 @@ stages:
displayName: Gradle Build
inputs:
jdkVersionOption: 1.11
- job: kubernetes
displayName: Kubernetes
pool:
vmImage: ubuntu-latest
steps:
- task: ShellScript@2
displayName: Generate Staging Manifest
inputs:
scriptPath: ./yttw.sh
args: >
-f kubernetes
-v image_tag=$(Build.BuildId)
-v args=debug
--output-files manifests/staging
- task: ShellScript@2
displayName: Generate Production Manifest
inputs:
scriptPath: ./yttw.sh
args: >
-f kubernetes
-v image_tag=$(Build.BuildId)
-v replica_count=2
--output-files manifests/production
- task: PublishPipelineArtifact@1
displayName: Publish Manifests
inputs:
targetPath: manifests
artifactName: manifests
- stage: Deploy
displayName: Deploy
dependsOn: assemble
condition:
not(eq(variables['build.reason'], 'PullRequest'))
jobs:
- job: push
displayName: Push
pool:
vmImage: ubuntu-latest
steps:
- task: Docker@2
displayName: Build and Push
inputs:
command: buildAndPush
containerRegistry: SteeltoeContainerRegistry
repository: initializr-config-server
tags: |
$(Build.BuildId)
latest

Просмотреть файл

@ -1,10 +0,0 @@
---
applications:
- name: initializr-config-server
buildpacks:
- https://github.com/cloudfoundry/java-buildpack.git#v4.32.1
path: ../../build/libs/Steeltoe.InitializrConfigServer-0.1.0-SNAPSHOT.jar
memory: 1024M
env:
JBP_CONFIG_JAVA_MAIN: '{ arguments: "--logging.level.org.springframework.web=debug" }'
JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'

Просмотреть файл

@ -1,23 +0,0 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: initializr-config-server
spec:
replicas: 1
selector:
matchLabels:
app: initializr-config-server
template:
metadata:
labels:
app: initializr-config-server
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: initializr-config-server
image: localhost:5000/initializr-config-server
args: ["--debug"]
ports:
- containerPort: 8888

Просмотреть файл

@ -1,11 +0,0 @@
---
apiVersion: v1
kind: Service
metadata:
name: initializr-config-server
spec:
ports:
- port: 80
targetPort: 8888
selector:
app: initializr-config-server

10
kubernetes/defaults.yaml Normal file
Просмотреть файл

@ -0,0 +1,10 @@
#@data/values-schema
#@schema/type any=True
---
name: initializr-config-server
image_name: steeltoe.azurecr.io/initializr-config-server
image_tag: latest
container_port: 8888
service_port: 80
replica_count: 1
args: ""

37
kubernetes/manifest.yaml Normal file
Просмотреть файл

@ -0,0 +1,37 @@
#@ load("@ytt:data", "data")
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: #@ data.values.name
spec:
selector:
matchLabels:
app: #@ data.values.name
template:
metadata:
labels:
app: #@ data.values.name
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: #@ data.values.name
image: #@ "{}:{}".format(data.values.image_name, data.values.image_tag)
ports:
- containerPort: #@ int(data.values.container_port)
#@ if/end data.values.args:
args: #@ data.values.args.split()
replicas: #@ int(data.values.replica_count)
---
apiVersion: v1
kind: Service
metadata:
name: #@ data.values.name
spec:
ports:
- port: #@ int(data.values.service_port)
targetPort: #@ int(data.values.container_port)
selector:
app: #@ data.values.name

2
tool.properties Normal file
Просмотреть файл

@ -0,0 +1,2 @@
ytt_version=v0.36.0
ytt_mirror=https://github.com/vmware-tanzu/carvel-ytt/releases/download

29
yttw.sh Executable file
Просмотреть файл

@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e
# =========================================================================== #
# wrapper for ytt #
# =========================================================================== #
base_dir=$(dirname $0)
ytt=$base_dir/tools/ytt
if [ ! -x $ytt ]; then
ytt_version=$(grep '^ytt_version=' $base_dir/tool.properties | cut -d= -f2)
ytt_mirror=$(grep '^ytt_mirror=' $base_dir/tool.properties | cut -d= -f2)
case $(uname -s) in
Darwin) platform=darwin ;;
Linux) platform=linux ;;
*)
echo "unsupported platform: $(uname -s)"
exit 1
;;
esac
ytt_url=$ytt_mirror/$ytt_version/ytt-$platform-amd64
mkdir -p $(dirname $ytt)
wget $ytt_url -O $ytt
chmod +x $ytt
fi
exec $ytt $*