我的镜像是nginx,请帮我写一个yaml文件
时间: 2024-06-11 18:08:40 浏览: 128
这是一个基本的nginx镜像的yaml文件,你可以根据自己的需求进行修改:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: nginx-html
mountPath: /usr/share/nginx/html
volumes:
- name: nginx-config
configMap:
name: nginx-config
- name: nginx-html
persistentVolumeClaim:
claimName: nginx-html
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx.conf: |
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-html
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
```
这个yaml文件包含了一个Deployment,一个ConfigMap和一个PersistentVolumeClaim。Deployment中的容器使用了nginx镜像,并挂载了ConfigMap中的nginx.conf文件和PersistentVolumeClaim中的存储卷。nginx.conf文件中配置了一个简单的HTTP服务器,可以提供静态文件服务。PersistentVolumeClaim用于持久化存储nginx的静态文件。
阅读全文