新增learn-kubernetes(https://github.com/yyong-brs/learn-kubernetes)相关文件
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
|
||||
$url = $(kubectl get svc vweb -o jsonpath='http://{.status.loadBalancer.ingress[0].*}:8090/v.txt')
|
||||
|
||||
for($i = 0; $i -lt 10; $i++) {
|
||||
curl -s "$url"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
URL=$(kubectl get svc vweb -o jsonpath='http://{.status.loadBalancer.ingress[0].*}:8090/v.txt')
|
||||
|
||||
for i in {1..10}
|
||||
do
|
||||
curl -s "$URL"
|
||||
done
|
||||
@@ -0,0 +1,11 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
ch09-vweb-v1:
|
||||
image: kiamol/ch09-vweb:v1-linux-amd64
|
||||
|
||||
ch09-vweb-v2:
|
||||
image: kiamol/ch09-vweb:v2-linux-amd64
|
||||
|
||||
ch09-vweb-v3:
|
||||
image: kiamol/ch09-vweb:v3-linux-amd64
|
||||
@@ -0,0 +1,11 @@
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
ch09-vweb-v1:
|
||||
image: kiamol/ch09-vweb:v1-linux-arm64
|
||||
|
||||
ch09-vweb-v2:
|
||||
image: kiamol/ch09-vweb:v2-linux-arm64
|
||||
|
||||
ch09-vweb-v3:
|
||||
image: kiamol/ch09-vweb:v3-linux-arm64
|
||||
@@ -0,0 +1,17 @@
|
||||
version: "3.6"
|
||||
|
||||
services:
|
||||
ch09-vweb-v1:
|
||||
image: kiamol/ch09-vweb:v1
|
||||
build:
|
||||
context: ./vweb/v1
|
||||
|
||||
ch09-vweb-v2:
|
||||
image: kiamol/ch09-vweb:v2
|
||||
build:
|
||||
context: ./vweb/v2
|
||||
|
||||
ch09-vweb-v3:
|
||||
image: kiamol/ch09-vweb:v3
|
||||
build:
|
||||
context: ./vweb/v3
|
||||
@@ -0,0 +1,10 @@
|
||||
$images=$(yq e '.services.[].image' docker-compose.yml)
|
||||
|
||||
foreach ($image in $images)
|
||||
{
|
||||
docker manifest create --amend $image `
|
||||
"$($image)-linux-arm64" `
|
||||
"$($image)-linux-amd64"
|
||||
|
||||
docker manifest push $image
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
FROM nginx:1.21-alpine
|
||||
COPY *.html /usr/share/nginx/html/
|
||||
COPY *.txt /usr/share/nginx/html/
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>v1</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #a8ebff;
|
||||
font-family: "Lucida Console", Courier, monospace;
|
||||
}
|
||||
h1 {
|
||||
font-weight: 800;
|
||||
font-size: 80px;
|
||||
color: #020c66;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>v1</h1>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
v1
|
||||
@@ -0,0 +1,3 @@
|
||||
FROM nginx:1.21-alpine
|
||||
COPY *.html /usr/share/nginx/html/
|
||||
COPY *.txt /usr/share/nginx/html/
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>v2</title>
|
||||
<style>
|
||||
body {
|
||||
background-color: #b3ffe6;
|
||||
font-family: "Times New Roman", Times, serif;
|
||||
}
|
||||
h1 {
|
||||
font-size: 90px;
|
||||
color: #02422d;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>v2</h1>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
v2
|
||||
@@ -0,0 +1,3 @@
|
||||
FROM alpine:3.15
|
||||
|
||||
CMD this-will-fail
|
||||
49
learn/learn-kubernetes-master/kiamol/ch09/lab/README.md
Normal file
49
learn/learn-kubernetes-master/kiamol/ch09/lab/README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Ch09 lab
|
||||
|
||||
Run v1 of the app:
|
||||
|
||||
```
|
||||
kubectl apply -f lab/v1/
|
||||
```
|
||||
|
||||
Get the URL and browse:
|
||||
|
||||
```
|
||||
kubectl get svc vweb -o jsonpath='http://{.status.loadBalancer.ingress[0].*}:8090'
|
||||
```
|
||||
|
||||
> v1 is the blue deployment
|
||||
|
||||
## Sample Solution
|
||||
|
||||
My [v2 Deployment](solution/vweb-v2.yaml) runs four Pods from the v2 image. It's a new Deployment object, not an update to the existing v1 Deployment.
|
||||
|
||||
My [Service update](solution/vweb-service-v2.yaml) changes the label selector in the existing service to point to the Pods in the v2 Deployment.
|
||||
|
||||
```
|
||||
kubectl apply -f lab/solution/
|
||||
```
|
||||
|
||||
> v2 is the green deployment
|
||||
|
||||
You can flip between blue and green by updating just the Service:
|
||||
|
||||
```
|
||||
# for v1
|
||||
kubectl apply -f lab/v1/vweb-service-v1.yaml
|
||||
```
|
||||
|
||||
```
|
||||
# for v2
|
||||
kubectl apply -f lab/solution/vweb-service-v2.yaml
|
||||
```
|
||||
|
||||
> Your browser may cache the response, so be sure to do a full refresh (usually Ctrl-F5 on Windows and Cmd+Shift+R on Mac)
|
||||
|
||||
## Teardown
|
||||
|
||||
Delete the lab resources by their labels:
|
||||
|
||||
```
|
||||
kubectl delete all -l kiamol=ch09-lab
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09-lab
|
||||
spec:
|
||||
ports:
|
||||
- port: 8090
|
||||
targetPort: http
|
||||
selector:
|
||||
app: vweb
|
||||
version: v2
|
||||
type: LoadBalancer
|
||||
@@ -0,0 +1,26 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb-v2
|
||||
labels:
|
||||
kiamol: ch09-lab
|
||||
app: vweb
|
||||
spec:
|
||||
replicas: 4
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
version: v2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v2
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09-lab
|
||||
spec:
|
||||
ports:
|
||||
- port: 8090
|
||||
targetPort: http
|
||||
selector:
|
||||
app: vweb
|
||||
version: v1
|
||||
type: LoadBalancer
|
||||
@@ -0,0 +1,26 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb-v1
|
||||
labels:
|
||||
kiamol: ch09-lab
|
||||
app: vweb
|
||||
spec:
|
||||
replicas: 4
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
version: v1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: todo-db-config
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
primary.conf: |-
|
||||
listen_addresses = '*'
|
||||
max_connections = 100
|
||||
shared_buffers = 128MB
|
||||
dynamic_shared_memory_type = posix
|
||||
log_timezone = 'UTC'
|
||||
datestyle = 'iso, mdy'
|
||||
timezone = 'UTC'
|
||||
lc_messages = 'en_US.utf8'
|
||||
lc_monetary = 'en_US.utf8'
|
||||
lc_numeric = 'en_US.utf8'
|
||||
lc_time = 'en_US.utf8'
|
||||
default_text_search_config = 'pg_catalog.english'
|
||||
wal_level = hot_standby
|
||||
max_wal_senders = 5
|
||||
wal_keep_segments = 32
|
||||
standby.conf: |-
|
||||
listen_addresses = '*'
|
||||
max_connections = 100
|
||||
shared_buffers = 128MB
|
||||
dynamic_shared_memory_type = posix
|
||||
log_timezone = 'UTC'
|
||||
datestyle = 'iso, mdy'
|
||||
timezone = 'UTC'
|
||||
lc_messages = 'en_US.utf8'
|
||||
lc_monetary = 'en_US.utf8'
|
||||
lc_numeric = 'en_US.utf8'
|
||||
lc_time = 'en_US.utf8'
|
||||
default_text_search_config = 'pg_catalog.english'
|
||||
hot_standby = on
|
||||
pg_hba.conf: |-
|
||||
# "local" is for Unix domain socket connections only
|
||||
local all all trust
|
||||
# IPv4 local connections:
|
||||
host all all 127.0.0.1/32 trust
|
||||
# IPv6 local connections:
|
||||
host all all ::1/128 trust
|
||||
# Allow replication connections from localhost, by a user with the
|
||||
# replication privilege.
|
||||
local replication all trust
|
||||
host replication all 127.0.0.1/32 trust
|
||||
host replication all ::1/128 trust
|
||||
host replication replication all md5
|
||||
host all all all md5
|
||||
@@ -0,0 +1,10 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: todo-db-env
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
POSTGRES_PRIMARY_NAME: "todo-db-0"
|
||||
POSTGRES_PRIMARY_FQDN: "todo-db-0.todo-db.default.svc.cluster.local"
|
||||
POSTGRES_SECONDARY_FQDN: "todo-db-1.todo-db.default.svc.cluster.local"
|
||||
@@ -0,0 +1,44 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: todo-db-scripts
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
wait-service.sh: |-
|
||||
#!/bin/sh
|
||||
if [ "$HOSTNAME" == "$POSTGRES_PRIMARY_NAME" ]; then
|
||||
echo '** Postgres primary **'
|
||||
else
|
||||
echo '** Postgres standby - waiting on DNS for primary **'
|
||||
until nslookup ${POSTGRES_PRIMARY_FQDN}; do echo Waiting for ${POSTGRES_PRIMARY_FQDN}; sleep 1; done
|
||||
fi
|
||||
initialize-replication.sh: |-
|
||||
#!/bin/bash
|
||||
if [ "$HOSTNAME" == "$POSTGRES_PRIMARY_NAME" ]; then
|
||||
echo '** Postgres primary - creating replication user script **'
|
||||
cp /scripts/create-replica-user.sh /docker-entrypoint-initdb.d/create-replica-user.sh
|
||||
ls -l /docker-entrypoint-initdb.d
|
||||
else
|
||||
echo '** Postgres standby - waiting on primary **'
|
||||
until pg_isready -h "$POSTGRES_PRIMARY_FQDN"; do echo Waiting for db to be ready; sleep 1; done
|
||||
fi
|
||||
create-replica-user.sh: |-
|
||||
#!/bin/bash
|
||||
set -e
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
CREATE ROLE replication WITH REPLICATION PASSWORD '$PGPASSWORD' LOGIN
|
||||
EOSQL
|
||||
startup.sh: |-
|
||||
#!/bin/sh
|
||||
if [ "$HOSTNAME" == "$POSTGRES_PRIMARY_NAME" ]; then
|
||||
echo '** Postgres primary **'
|
||||
/docker-entrypoint.sh postgres -c config_file=/conf/primary.conf -c hba_file=/conf/pg_hba.conf
|
||||
else
|
||||
echo '** Postgres standby - initializing replication**'
|
||||
if [ -z "$(ls -A ${PGDATA})" ]; then
|
||||
pg_basebackup -R -h "$POSTGRES_PRIMARY_FQDN" -D "$PGDATA" -P -U replication
|
||||
chown -R postgres:postgres $PGDATA
|
||||
fi
|
||||
/docker-entrypoint.sh postgres -c config_file=/conf/standby.conf
|
||||
fi
|
||||
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: todo-db-secret
|
||||
labels:
|
||||
kiamol: ch09
|
||||
type: Opaque
|
||||
stringData:
|
||||
POSTGRES_PASSWORD: "kiamol-2*2*"
|
||||
@@ -0,0 +1,14 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: todo-db
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
ports:
|
||||
- port: 5432
|
||||
targetPort: 5432
|
||||
name: postgres
|
||||
selector:
|
||||
app: todo-db
|
||||
clusterIP: None
|
||||
@@ -0,0 +1,99 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: todo-db
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-db
|
||||
serviceName: todo-db
|
||||
replicas: 2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-db
|
||||
spec:
|
||||
initContainers:
|
||||
- name: wait-service
|
||||
image: kiamol/ch03-sleep
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
command: ['/scripts/wait-service.sh']
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: initialize-replication
|
||||
image: postgres:11.6-alpine
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
env:
|
||||
- name: PGPASSWORD # used as replication password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: POSTGRES_PASSWORD
|
||||
name: todo-db-secret
|
||||
command: ['/scripts/initialize-replication.sh']
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
containers:
|
||||
- name: db
|
||||
image: postgres:11.6-alpine
|
||||
command: ["/scripts/startup.sh"]
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD_FILE
|
||||
value: /secrets/postgres_password
|
||||
- name: PGPASSWORD # used as replication password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: POSTGRES_PASSWORD
|
||||
name: todo-db-secret
|
||||
volumeMounts:
|
||||
- name: secret
|
||||
mountPath: "/secrets"
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: config
|
||||
mountPath: "/conf"
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
volumes:
|
||||
- name: secret
|
||||
secret:
|
||||
secretName: todo-db-secret
|
||||
defaultMode: 0400
|
||||
items:
|
||||
- key: POSTGRES_PASSWORD
|
||||
path: postgres_password
|
||||
- name: scripts
|
||||
configMap:
|
||||
name: todo-db-scripts
|
||||
defaultMode: 0555
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-db-config
|
||||
defaultMode: 0444
|
||||
- name: initdb
|
||||
emptyDir: {}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 50Mi
|
||||
@@ -0,0 +1,103 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: todo-db
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-db
|
||||
serviceName: todo-db
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
partition: 1 # only updates Pod 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-db
|
||||
spec:
|
||||
initContainers:
|
||||
- name: wait-service
|
||||
image: kiamol/ch03-sleep
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
command: ['/scripts/wait-service.sh']
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: initialize-replication
|
||||
image: postgres:11.8-alpine
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
env:
|
||||
- name: PGPASSWORD # used as replication password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: POSTGRES_PASSWORD
|
||||
name: todo-db-secret
|
||||
command: ['/scripts/initialize-replication.sh']
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
containers:
|
||||
- name: db
|
||||
image: postgres:11.8-alpine
|
||||
command: ["/scripts/startup.sh"]
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD_FILE
|
||||
value: /secrets/postgres_password
|
||||
- name: PGPASSWORD # used as replication password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: POSTGRES_PASSWORD
|
||||
name: todo-db-secret
|
||||
volumeMounts:
|
||||
- name: secret
|
||||
mountPath: "/secrets"
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: config
|
||||
mountPath: "/conf"
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
volumes:
|
||||
- name: secret
|
||||
secret:
|
||||
secretName: todo-db-secret
|
||||
defaultMode: 0400
|
||||
items:
|
||||
- key: POSTGRES_PASSWORD
|
||||
path: postgres_password
|
||||
- name: scripts
|
||||
configMap:
|
||||
name: todo-db-scripts
|
||||
defaultMode: 0555
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-db-config
|
||||
defaultMode: 0444
|
||||
- name: initdb
|
||||
emptyDir: {}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 50Mi
|
||||
@@ -0,0 +1,101 @@
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: todo-db
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-db
|
||||
serviceName: todo-db
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-db
|
||||
spec:
|
||||
initContainers:
|
||||
- name: wait-service
|
||||
image: kiamol/ch03-sleep
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
command: ['/scripts/wait-service.sh']
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: initialize-replication
|
||||
image: postgres:11.8-alpine
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
env:
|
||||
- name: PGPASSWORD # used as replication password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: POSTGRES_PASSWORD
|
||||
name: todo-db-secret
|
||||
command: ['/scripts/initialize-replication.sh']
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
containers:
|
||||
- name: db
|
||||
image: postgres:11.8-alpine
|
||||
command: ["/scripts/startup.sh"]
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: todo-db-env
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD_FILE
|
||||
value: /secrets/postgres_password
|
||||
- name: PGPASSWORD # used as replication password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
key: POSTGRES_PASSWORD
|
||||
name: todo-db-secret
|
||||
volumeMounts:
|
||||
- name: secret
|
||||
mountPath: "/secrets"
|
||||
- name: scripts
|
||||
mountPath: "/scripts"
|
||||
- name: config
|
||||
mountPath: "/conf"
|
||||
- name: initdb
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
volumes:
|
||||
- name: secret
|
||||
secret:
|
||||
secretName: todo-db-secret
|
||||
defaultMode: 0400
|
||||
items:
|
||||
- key: POSTGRES_PASSWORD
|
||||
path: postgres_password
|
||||
- name: scripts
|
||||
configMap:
|
||||
name: todo-db-scripts
|
||||
defaultMode: 0555
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-db-config
|
||||
defaultMode: 0444
|
||||
- name: initdb
|
||||
emptyDir: {}
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 50Mi
|
||||
@@ -0,0 +1,45 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: todo-proxy-configmap
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
nginx.conf: |-
|
||||
user nginx;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:1m inactive=24h max_size=1g;
|
||||
|
||||
gzip on;
|
||||
gzip_proxied any;
|
||||
|
||||
map $sent_http_content_type $expires {
|
||||
default off;
|
||||
~image/ 6M;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
location / {
|
||||
proxy_pass http://todo-web;
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache STATIC;
|
||||
proxy_cache_valid 200 10s;
|
||||
proxy_cache_use_stale error timeout invalid_header updating
|
||||
http_500 http_502 http_503 http_504;
|
||||
add_header X-Cache $upstream_cache_status;
|
||||
add_header X-Host $hostname;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: todo-proxy
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
ports:
|
||||
- port: 8091
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: todo-proxy
|
||||
type: LoadBalancer
|
||||
@@ -0,0 +1,33 @@
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: todo-proxy
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-proxy
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-proxy
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.17-alpine
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: "/etc/nginx/"
|
||||
readOnly: true
|
||||
- name: cache-volume
|
||||
mountPath: /data/nginx/cache
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-proxy-configmap
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
@@ -0,0 +1,38 @@
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
name: todo-proxy
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-proxy
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
minReadySeconds: 90
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-proxy
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx:1.18-alpine
|
||||
name: nginx
|
||||
ports:
|
||||
- containerPort: 80
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: "/etc/nginx/"
|
||||
readOnly: true
|
||||
- name: cache-volume
|
||||
mountPath: /data/nginx/cache
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-proxy-configmap
|
||||
- name: cache-volume
|
||||
emptyDir: {}
|
||||
@@ -0,0 +1,16 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: todo-web-config
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
config.json: |-
|
||||
{
|
||||
"ConfigController": {
|
||||
"Enabled" : true
|
||||
},
|
||||
"Database" : {
|
||||
"Provider" : "Postgres"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: todo-web-secret
|
||||
labels:
|
||||
kiamol: ch09
|
||||
type: Opaque
|
||||
stringData:
|
||||
secrets.json: |-
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"ToDoDb": "Server=todo-db-0.todo-db.default.svc.cluster.local;Database=todo;User Id=postgres;Password=kiamol-2*2*;",
|
||||
"ToDoDb-ReadOnly": "Server=todo-db-1.todo-db.default.svc.cluster.local;Database=todo;User Id=postgres;Password=kiamol-2*2*;"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: todo-web
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: todo-web
|
||||
type: ClusterIP
|
||||
@@ -0,0 +1,42 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: todo-web
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-web
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-web
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch04-todo-list
|
||||
env:
|
||||
- name: ASPNETCORE_ENVIRONMENT
|
||||
value: Test
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: "/app/config"
|
||||
readOnly: true
|
||||
- name: secret
|
||||
mountPath: "/app/secrets"
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-web-config
|
||||
items:
|
||||
- key: config.json
|
||||
path: config.json
|
||||
- name: secret
|
||||
secret:
|
||||
secretName: todo-web-secret
|
||||
defaultMode: 0400
|
||||
items:
|
||||
- key: secrets.json
|
||||
path: secrets.json
|
||||
@@ -0,0 +1,44 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: todo-web
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-web
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-web
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch04-todo-list
|
||||
env:
|
||||
- name: ASPNETCORE_ENVIRONMENT
|
||||
value: Test
|
||||
- name: Database__ReadOnly
|
||||
value: "true"
|
||||
volumeMounts:
|
||||
- name: config
|
||||
mountPath: "/app/config"
|
||||
readOnly: true
|
||||
- name: secret
|
||||
mountPath: "/app/secrets"
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: config
|
||||
configMap:
|
||||
name: todo-web-config
|
||||
items:
|
||||
- key: config.json
|
||||
path: config.json
|
||||
- name: secret
|
||||
secret:
|
||||
secretName: todo-web-secret
|
||||
defaultMode: 0400
|
||||
items:
|
||||
- key: secrets.json
|
||||
path: secrets.json
|
||||
@@ -0,0 +1,30 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 4
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
minReadySeconds: 60
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
maxSurge: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v2
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
ports:
|
||||
- port: 8090
|
||||
targetPort: http
|
||||
selector:
|
||||
app: vweb
|
||||
type: LoadBalancer
|
||||
@@ -0,0 +1,30 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 4
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
minReadySeconds: 60
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
maxSurge: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v2
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v3
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v3
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 0
|
||||
maxSurge: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v2
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
minReadySeconds: 30
|
||||
progressDeadlineSeconds: 120
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxUnavailable: 1
|
||||
maxSurge: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v3
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v3
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: vweb-config
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
v.txt:
|
||||
v3.1
|
||||
@@ -0,0 +1,24 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v1.1
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v2
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: vweb-config
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
v.txt:
|
||||
v3-from-config
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v3
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
volumeMounts:
|
||||
- name: static
|
||||
mountPath: "/usr/share/nginx/html/"
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: static
|
||||
configMap:
|
||||
name: vweb-config
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: vweb-config-v4
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
v.txt:
|
||||
v4-from-config
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v4
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
volumeMounts:
|
||||
- name: static
|
||||
mountPath: "/usr/share/nginx/html/"
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: static
|
||||
configMap:
|
||||
name: vweb-config-v4
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: vweb-config-v41
|
||||
labels:
|
||||
kiamol: ch09
|
||||
data:
|
||||
v.txt:
|
||||
v4.1-from-config
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v4.1
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v2
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
volumeMounts:
|
||||
- name: static
|
||||
mountPath: "/usr/share/nginx/html/"
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: static
|
||||
configMap:
|
||||
name: vweb-config-v41
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
ports:
|
||||
- port: 8090
|
||||
targetPort: http
|
||||
selector:
|
||||
app: vweb
|
||||
type: LoadBalancer
|
||||
24
learn/learn-kubernetes-master/kiamol/ch09/vweb/vweb-v1.yaml
Normal file
24
learn/learn-kubernetes-master/kiamol/ch09/vweb/vweb-v1.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vweb
|
||||
labels:
|
||||
kiamol: ch09
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vweb
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vweb
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: kiamol/ch09-vweb:v1
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
|
||||
Reference in New Issue
Block a user