-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
557 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
codelab/01_kpt-validate/resources/sample-app/config/frontend/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: frontend | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: guestbook | ||
tier: frontend | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: guestbook | ||
tier: frontend | ||
spec: | ||
containers: | ||
- name: php-redis | ||
image: "frontend" | ||
resources: | ||
requests: | ||
cpu: 100m | ||
memory: 100Mi | ||
env: | ||
- name: GET_HOSTS_FROM | ||
value: env | ||
ports: | ||
- containerPort: 80 |
3 changes: 3 additions & 0 deletions
3
codelab/01_kpt-validate/resources/sample-app/config/frontend/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resources: | ||
- service.yaml | ||
- deployment.yaml |
14 changes: 14 additions & 0 deletions
14
codelab/01_kpt-validate/resources/sample-app/config/frontend/service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: frontend | ||
labels: | ||
app: guestbook | ||
tier: frontend | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- port: 80 | ||
selector: | ||
app: guestbook | ||
tier: frontend |
2 changes: 2 additions & 0 deletions
2
codelab/01_kpt-validate/resources/sample-app/config/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- frontend |
30 changes: 30 additions & 0 deletions
30
codelab/01_kpt-validate/resources/sample-app/php-redis/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2016 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM php:5-apache | ||
|
||
RUN apt-get update | ||
RUN pear channel-discover pear.nrk.io | ||
RUN pear install nrk/Predis | ||
|
||
# If the container's stdio is connected to systemd-journald, | ||
# /proc/self/fd/{1,2} are Unix sockets and apache will not be able to open() | ||
# them. Use "cat" to write directly to the already opened fds without opening | ||
# them again. | ||
RUN sed -i 's#ErrorLog /proc/self/fd/2#ErrorLog "|$/bin/cat 1>\&2"#' /etc/apache2/apache2.conf | ||
RUN sed -i 's#CustomLog /proc/self/fd/1 combined#CustomLog "|/bin/cat" combined#' /etc/apache2/apache2.conf | ||
|
||
ADD guestbook.php /var/www/html/guestbook.php | ||
ADD controllers.js /var/www/html/controllers.js | ||
ADD index.html /var/www/html/index.html |
80 changes: 80 additions & 0 deletions
80
codelab/01_kpt-validate/resources/sample-app/php-redis/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright 2017 The Kubernetes Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
TAG = v6 | ||
REGISTRY = gcr.io/yuwenma-gke-playground | ||
ARCH ?= $(shell go env GOARCH) | ||
ALL_ARCH = amd64 arm arm64 ppc64le | ||
|
||
QEMUVERSION=v2.7.0 | ||
|
||
IMAGE = $(REGISTRY)/gb-frontend | ||
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) | ||
|
||
# Set default base image dynamically for each arch | ||
ifeq ($(ARCH),arm) | ||
QEMUARCH=arm | ||
BASEIMAGE=armhf/php:5.6-apache | ||
endif | ||
ifeq ($(ARCH),arm64) | ||
QEMUARCH=aarch64 | ||
BASEIMAGE=arm64v8/php:5-apache | ||
endif | ||
ifeq ($(ARCH),ppc64le) | ||
QEMUARCH=ppc64le | ||
BASEIMAGE=ppc64le/php:5-apache | ||
endif | ||
|
||
TEMP_DIR := $(shell mktemp -d) | ||
|
||
all: all-container | ||
|
||
sub-container-%: | ||
$(MAKE) ARCH=$* container | ||
|
||
sub-push-%: | ||
$(MAKE) ARCH=$* push | ||
|
||
all-container: $(addprefix sub-container-,$(ALL_ARCH)) | ||
|
||
all-push: $(addprefix sub-push-,$(ALL_ARCH)) | ||
docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g") | ||
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done | ||
docker manifest push --purge ${IMAGE}:${TAG} | ||
|
||
container: .container-$(ARCH) | ||
.container-$(ARCH): | ||
cp ./* $(TEMP_DIR) | ||
|
||
ifneq ($(ARCH),amd64) | ||
cd $(TEMP_DIR) && sed -i "s|FROM php.*|FROM $(BASEIMAGE)\nCOPY qemu-$(QEMUARCH)-static /usr/bin\n|g" Dockerfile | ||
# Register /usr/bin/qemu-ARCH-static as the handler for ARM binaries in the kernel | ||
docker run --rm --privileged multiarch/qemu-user-static:register --reset | ||
curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR) | ||
endif | ||
docker build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR) | ||
|
||
ifeq ($(ARCH), amd64) | ||
# This is for to maintain the backward compatibility | ||
docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG) | ||
endif | ||
|
||
push: .push-$(ARCH) | ||
.push-$(ARCH): .container-$(ARCH) | ||
docker push $(MULTI_ARCH_IMG):$(TAG) | ||
|
||
clean: $(addprefix sub-clean-,$(ALL_ARCH)) | ||
docker rmi -f $(IMAGE):$(TAG) || true | ||
sub-clean-%: | ||
docker rmi -f $(IMAGE)-$*:$(TAG) || true |
29 changes: 29 additions & 0 deletions
29
codelab/01_kpt-validate/resources/sample-app/php-redis/controllers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var redisApp = angular.module('redis', ['ui.bootstrap']); | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
function RedisController() {} | ||
|
||
RedisController.prototype.onRedis = function() { | ||
this.scope_.messages.push(this.scope_.msg); | ||
this.scope_.msg = ""; | ||
var value = this.scope_.messages.join(); | ||
this.http_.get("guestbook.php?cmd=set&key=messages&value=" + value) | ||
.success(angular.bind(this, function(data) { | ||
this.scope_.redisResponse = "Updated."; | ||
})); | ||
}; | ||
|
||
redisApp.controller('RedisCtrl', function ($scope, $http, $location) { | ||
$scope.controller = new RedisController(); | ||
$scope.controller.scope_ = $scope; | ||
$scope.controller.location_ = $location; | ||
$scope.controller.http_ = $http; | ||
|
||
$scope.controller.http_.get("guestbook.php?cmd=get&key=messages") | ||
.success(function(data) { | ||
console.log(data); | ||
$scope.messages = data.data.split(","); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
codelab/01_kpt-validate/resources/sample-app/php-redis/guestbook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
error_reporting(E_ALL); | ||
ini_set('display_errors', 1); | ||
|
||
require 'Predis/Autoloader.php'; | ||
|
||
Predis\Autoloader::register(); | ||
|
||
if (isset($_GET['cmd']) === true) { | ||
$host = 'redis-master'; | ||
if (getenv('GET_HOSTS_FROM') == 'env') { | ||
$host = getenv('REDIS_MASTER_SERVICE_HOST'); | ||
} | ||
header('Content-Type: application/json'); | ||
if ($_GET['cmd'] == 'set') { | ||
$client = new Predis\Client([ | ||
'scheme' => 'tcp', | ||
'host' => $host, | ||
'port' => 6379, | ||
]); | ||
|
||
$client->set($_GET['key'], $_GET['value']); | ||
print('{"message": "Updated"}'); | ||
} else { | ||
$host = 'redis-slave'; | ||
if (getenv('GET_HOSTS_FROM') == 'env') { | ||
$host = getenv('REDIS_SLAVE_SERVICE_HOST'); | ||
} | ||
$client = new Predis\Client([ | ||
'scheme' => 'tcp', | ||
'host' => $host, | ||
'port' => 6379, | ||
]); | ||
|
||
$value = $client->get($_GET['key']); | ||
print('{"data": "' . $value . '"}'); | ||
} | ||
} else { | ||
phpinfo(); | ||
} ?> |
25 changes: 25 additions & 0 deletions
25
codelab/01_kpt-validate/resources/sample-app/php-redis/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html ng-app="redis"> | ||
<head> | ||
<title>Hello World</title> | ||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> | ||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script> | ||
<script src="controllers.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js"></script> | ||
</head> | ||
<body ng-controller="RedisCtrl"> | ||
<div style="width: 50%; margin-left: 20px"> | ||
<h2>Hello World YES!</h2> | ||
<form> | ||
<fieldset> | ||
<input ng-model="msg" placeholder="Messages" class="form-control" type="text" name="input"><br> | ||
<button type="button" class="btn btn-primary" ng-click="controller.onRedis()">Submit</button> | ||
</fieldset> | ||
</form> | ||
<div> | ||
<div ng-repeat="msg in messages track by $index"> | ||
{{msg}} | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
codelab/01_kpt-validate/resources/sample-app/skaffold.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: skaffold/v2beta8 | ||
kind: Config | ||
metadata: | ||
name: kpt-cl | ||
build: | ||
artifacts: | ||
- image: "frontend" | ||
context: php-redis | ||
deploy: | ||
kpt: | ||
dir: config |
9 changes: 9 additions & 0 deletions
9
codelab/01_kpt-validate/resources/validation-kubeval/fn-kubeval.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: kubeval | ||
annotations: | ||
config.kubernetes.io/function: | | ||
container: | ||
image: gcr.io/kpt-functions/kubeval | ||
network: true |
21 changes: 21 additions & 0 deletions
21
codelab/01_kpt-validate/resources/validation-pipeline/fn-pipeline.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
# Validates the yaml schema. | ||
name: YamlValidate | ||
annotations: | ||
config.kubernetes.io/function: | | ||
container: | ||
image: gcr.io/kpt-functions/kubeval | ||
network: true | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
# Validates that all containers have cpu and memory reservations set. | ||
name: CPUAndMemory | ||
annotations: | ||
config.kubernetes.io/function: | | ||
container: | ||
image: gcr.io/kustomize-functions/example-validator-kubeval:v0.1.0 | ||
network: true |
28 changes: 28 additions & 0 deletions
28
codelab/02_kpt-deploy/resources/sample-app/config/frontend/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: frontend | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: guestbook | ||
tier: frontend | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: guestbook | ||
tier: frontend | ||
spec: | ||
containers: | ||
- name: php-redis | ||
image: "frontend" | ||
resources: | ||
requests: | ||
cpu: 100m | ||
memory: 100Mi | ||
env: | ||
- name: GET_HOSTS_FROM | ||
value: env | ||
ports: | ||
- containerPort: 80 |
3 changes: 3 additions & 0 deletions
3
codelab/02_kpt-deploy/resources/sample-app/config/frontend/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resources: | ||
- service.yaml | ||
- deployment.yaml |
14 changes: 14 additions & 0 deletions
14
codelab/02_kpt-deploy/resources/sample-app/config/frontend/service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: frontend | ||
labels: | ||
app: guestbook | ||
tier: frontend | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- port: 80 | ||
selector: | ||
app: guestbook | ||
tier: frontend |
2 changes: 2 additions & 0 deletions
2
codelab/02_kpt-deploy/resources/sample-app/config/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- frontend |
30 changes: 30 additions & 0 deletions
30
codelab/02_kpt-deploy/resources/sample-app/php-redis/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2016 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM php:5-apache | ||
|
||
RUN apt-get update | ||
RUN pear channel-discover pear.nrk.io | ||
RUN pear install nrk/Predis | ||
|
||
# If the container's stdio is connected to systemd-journald, | ||
# /proc/self/fd/{1,2} are Unix sockets and apache will not be able to open() | ||
# them. Use "cat" to write directly to the already opened fds without opening | ||
# them again. | ||
RUN sed -i 's#ErrorLog /proc/self/fd/2#ErrorLog "|$/bin/cat 1>\&2"#' /etc/apache2/apache2.conf | ||
RUN sed -i 's#CustomLog /proc/self/fd/1 combined#CustomLog "|/bin/cat" combined#' /etc/apache2/apache2.conf | ||
|
||
ADD guestbook.php /var/www/html/guestbook.php | ||
ADD controllers.js /var/www/html/controllers.js | ||
ADD index.html /var/www/html/index.html |
Oops, something went wrong.