标签:contain selector nod tor mes Nginx部署 api deploy 创建
k8s-部署nginxapiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1 # tells deployment to run 2 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: nginx
spec:
nodeSelector:
kubernetes.io/hostname: k8s-n1 #指定node运行
containers:
- name: nginx
image: nginx:1.7.9
ports:- containerPort: 80
volumeMounts: #pod 内部文配置文件映射到本机- name: nginxconf
mountPath: /etc/nginx/nginx.conf- name: nginxconfd
mountPath: /etc/nginx/conf.d- name: nginxlogs
mountPath: /var/log/nginx/log
volumes: #物理机文件目录- name: nginxconf
hostPath:
path: /data/nginx/nginx.conf- name: nginxconfd
hostPath:
path: /data/nginx/conf.d- name: nginxlogs
hostPath:
path: /data/nginx/logs
创建服务
apiVersion: v1
kind: Service
metadata:
name: nginx-server
labels:
name: nginx-server
spec:
ports:- port: 80
nodePort: 80
selector:
app: nginx
type: NodePort # 这个服务中使用了nodePort 意思是将服务暴露出去这样就可外部访问了
标签:contain selector nod tor mes Nginx部署 api deploy 创建
原文地址:https://blog.51cto.com/8175747/2360425