Skip to content

Instantly share code, notes, and snippets.

@minhnguyenvan95
Created June 7, 2022 08:22
Show Gist options
  • Select an option

  • Save minhnguyenvan95/5961ca5007a936252d843b04215a1233 to your computer and use it in GitHub Desktop.

Select an option

Save minhnguyenvan95/5961ca5007a936252d843b04215a1233 to your computer and use it in GitHub Desktop.
nginx k8s yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /etc/nginx
name: nginx-conf
readOnly: true
- mountPath: /var/log/nginx
name: log
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
items:
- key: nginx.conf
path: nginx.conf
- key: virtualhost.conf
path: virtualhost/virtualhost.conf
name: nginx-conf
name: nginx-conf
- emptyDir: {}
name: log
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
sessionAffinity: None
type: NodePort
---
apiVersion: v1
data:
nginx.conf: "user nginx;\nworker_processes 3;\nerror_log /var/log/nginx/error.log;\nevents
{\n worker_connections 10240;\n}\nhttp {\n log_format main\n 'remote_addr:$remote_addr\\t'\n
\ 'time_local:$time_local\\t'\n 'method:$request_method\\t'\n
\ 'uri:$request_uri\\t'\n 'host:$host\\t'\n 'status:$status\\t'\n
\ 'bytes_sent:$body_bytes_sent\\t'\n 'referer:$http_referer\\t'\n
\ 'useragent:$http_user_agent\\t'\n 'forwardedfor:$http_x_forwarded_for\\t'\n
\ 'request_time:$request_time';\n\n access_log\t/var/log/nginx/access.log
main;\n\n server {\n listen 80;\n server_name _;\n\n location
/ {\n root html;\n index index.html index.htm;\n }\n
\ }\n include /etc/nginx/virtualhost/virtualhost.conf;\n}\n"
virtualhost.conf: |
upstream app {
server service.namespace.svc.cluster.local:80;
keepalive 10240;
}
server {
listen 80 default_server;
root /usr/local/app;
access_log /var/log/nginx/app.access_log main;
error_log /var/log/nginx/app.error_log;
location / {
proxy_pass http://app;
proxy_http_version 1.1;
}
}
kind: ConfigMap
metadata:
name: nginx-conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment