Skip to content

Instantly share code, notes, and snippets.

@watawuwu
Created January 26, 2018 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watawuwu/5b47c17fabb015773766b8840380140f to your computer and use it in GitHub Desktop.
Save watawuwu/5b47c17fabb015773766b8840380140f to your computer and use it in GitHub Desktop.
NginxのGracefulShutdown
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: watawuwu/openresty-quit
ports:
- containerPort: 80
name: http
volumeMounts:
- name: nginx-volume
mountPath: /usr/local/openresty/nginx/conf
volumes:
- name: nginx-volume
configMap:
name: nginx-conf
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
error_log stderr debug;
events {
worker_connections 1024;
}
http {
server {
location /sleep {
default_type 'text/plain';
content_by_lua_block {
ngx.sleep(10)
ngx.say('Hello!!')
}
}
location / {
root html;
index index.html index.htm;
}
}
}
---
kind: Service
apiVersion: v1
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx
spec:
backend:
serviceName: nginx
servicePort: 80
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: openresty/openresty:xenial
ports:
- containerPort: 80
name: http
lifecycle:
preStop:
exec:
command: ["/usr/local/openresty/bin/openresty", "-s", "quit"]
volumeMounts:
- name: nginx-volume
mountPath: /usr/local/openresty/nginx/conf
volumes:
- name: nginx-volume
configMap:
name: nginx-conf
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
error_log stderr debug;
events {
worker_connections 1024;
}
http {
server {
location /sleep {
default_type 'text/plain';
content_by_lua_block {
ngx.sleep(10)
ngx.say('Hello!!')
}
}
location / {
root html;
index index.html index.htm;
}
}
}
---
kind: Service
apiVersion: v1
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx
spec:
backend:
serviceName: nginx
servicePort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment