目录
- 1.1 endpoint. yaml
- 1.2 glusterfs server. yaml
- 2.PV.yaml
- 3.PVC.yaml
- 4.Deployment.yaml
- 5.Pod.yaml
- 6.Service.yaml
- 7. StatefulSet.yaml
1.glusterfsPV.yaml
1.1 endpoint. yaml
apiVersion: v1
kind: Endpoints
metadata: ------------------------------------#元数据
name: glusterfs ----------------------------#ep名称
namespace: default -------------------------#命名空间
subsets: -------------------------------------#配置glusterfs连接信息
- addresses: ---------------------------------#添加glusterfs分布式地址
- ip: 10.0.0.14
- ip: 10.0.0.15
- ip: 10.0.0.16
ports: -------------------------------------#设定glusterfs服务端口
- port: 49152
protocol: TCP
1.2 glusterfs server. yaml
apiVersion: v1
kind: Service
metadata:
name: glusterfs
namespace: default
spec:
ports:
- port: 49152
protocol: TCP
targetPort: 49152
sessionAffinity: None ----------------------#是否支持session
type: ClusterIP
2.PV.yaml
apiVersion: v1
kind: PersistentVolume
metadata: -------------------------------------#元数据
name: tomcat-mysql --------------------------#pv名称
labels: -------------------------------------#标签信息
xxx: xxx
spec: -----------------------------------------#定义pv模板
capacity: -----------------------------------#定义pv容量
storage: 10Gi
accessModes: --------------------------------#访问模型;对象列表
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle ------#pvc解除绑定后,数据操作
=========================================================================================
nfs: ---------------------------------------#nfs挂载类型
path: "/data/tomcat" ----------------------#nfs服务目录
server: 172.16.20.101 ---------------------#nfs服务地址
readOnly: false ---------------------------#关闭只读
=========================================================================================
glusterfs: -------------------------------#glusterfs挂载类型
endpoints: "glusterfs" --------------------#端点类型 请保持与glusterfs ep服务名称一致。
path: "qiangge" ---------------------------#挂载目录 glusterfs文件名称
readOnly: false ---------------------------#关闭只读
3.PVC.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata: -------------------------------------#元数据
name: html ----------------------------------#pvc名称
namespace: xxxx -----------------------------#命名空间
spec: -----------------------------------------#pvc模板
selector: -----------------------------------#标签选择器
matchLabels: -----------------------------#必须与pv标签信息一致才可关联 如果不指定则随机匹配pv
xxx: xxx
accessModes: --------------------------------#访问模型;对象列表
- ReadWriteMany
resources: ----------------------------------#资源信息
requests: ---------------------------------#请求容量
storage: 99Gi
storageClassName: xxxx -----------------#存储类名称 注意1.5.2版本不可用
volumeMode: Filesystem ----------------------#卷模式为文件系统 注意1.5.2版本不可用
volumeName: pvc-ff926bb2-3029-4a08-b123-31a2ad1b6a19 --#卷名称
4.Deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata: ----------------------------------------#元数据
annotations: -------------------------------------#注释信息
deployment.kubernetes.io/revision: '1'
k8s.kuboard.cn/ingress: 'false'
k8s.kuboard.cn/service: NodePort
k8s.kuboard.cn/workload: nextcloud
labels:-------------------------------------------#标签信息
k8s.kuboard.cn/layer: ''
k8s.kuboard.cn/name: nextcloud
name: nextcloud-----------------------------------#名称
namespace: nextcloud------------------------------#命名空间
spec:-----------------------------------------------#定义容器模板,该模板可以包含多个容器
replicas: 3---------------------------------------#副本数量
selector:-----------------------------------------#标签选择器
matchLabels:
k8s.kuboard.cn/layer: ''
k8s.kuboard.cn/name: nextcloud
strategy:-----------------------------------------#滚动升级策略
type: RollingUpdate-----------------------------#类型
rollingUpdate:----------------------------------#由于replicas为3,则整个升级,pod个数在2-4个之间
maxSurge: 25%---------------------------------#滚动升级时会先启动25%pod
maxUnavailable: 25%---------------------------#滚动升级时允许的最大Unavailable的pod个数
template:
metadata: ------------------------------------#元数据
labels:---------------------------------------#标签
k8s.kuboard.cn/layer: ''
k8s.kuboard.cn/name: nextcloud
spec: ------------------------------------------#定义容器模板,该模板可以包含多个容器
containers: ----------------------------------#容器信息
- name: nextcloud --------------------------#容器名称
image: '172.16.20.100/library/nextcloud:yan'
imagePullPolicy: Always ------------------#镜像下载策略
ports:
- name: http
containerPort: 80
protocol: TCP
env
resources: -------------------------------#CPU内存限制
limits: --------------------------------#限制cpu内存
cpu: 200m
memory: 200m
requests: ------------------------------#请求cpu内存
cpu: 100m
memory: 100m
securityContext: -------------------------#安全设定
privileged: true -----------------------#开启享有特权
volumeMounts: ----------------------------#挂载volumes中定义的磁盘
- name: html ---------------------------#挂载容器1
mountPath: /var/www/html
- name: session ------------------------#挂载容器1
mountPath: /var/lib/php/session
volumes: ------------------------------------#在该pod上定义共享存储卷列表
- name: html -------------------------------#共享存储卷名称 (volumes类型有很多种)
persistentVolumeClaim: -------------------#volumes类型为pvc
claimName: html -----------------------#关联pvc名称
- name: session
persistentVolumeClaim:
claimName: session
restartPolicy: Always ------------------------#Pod的重启策略
schedulerName: default-scheduler -------------#指定pod调度到节点
5.Pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: django-pod
labels:
k8s-app: django
version: v1
kubernetes.io/cluster-service: "true"
annotations:
- name: String
spec:
restartPolicy: Always
nodeSelector:
containers:
- name: django-pod
image: django:v1.1
imagePullPolicy: Never
command: ['sh']
args: ["$(str)"]
env:
- name: str
value: "/etc/run.sh"
resources:
requests:
cpu: 0.1
memory: 32Mi
limits:
cpu: 0.5
memory: 32Mi
ports:
- containerPort: 8080
name: uwsgi
protocol: TCP
livenessProbe:
httpGet:
path: /
port: 8080
scheme: HTTP
initialDelaySeconds: 180
timeoutSeconds: 5
periodSeconds: 15
lifecycle:
postStart:
exec:
command:
- 'sh'
- 'yum upgrade -y'
preStop:
exec:
command: ['service httpd stop']
volumeMounts:
- name: volume
mountPath: /data
readOnly: True
volumes:
- name: volume
hostPath:
path: /opt
6.Service.yaml
apiVersion: v1
kind: Service
metadata: ---------------------------------#元数据
annotations: -----------------------------#注释信息
k8s.kuboard.cn/workload: nextcloud
labels: ----------------------------------#标签信息
k8s.kuboard.cn/layer: ''
k8s.kuboard.cn/name: nextcloud
name: nextcloud --------------------------#名称
namespace: nextcloud ---------------------#命名空间
spec: --------------------------------------#定义Service模板
clusterIP: 10.0.181.206 ------------------#指定svcip地址 不指定则随机
=================================================================================================
type: NodePort ---------------------------#类型为NodePort
ports:
- name: mnwwwp
nodePort: 30001 ----------------------#当type = NodePort时,指定映射到物理机的端口号
port: 80 -----------------------------#服务监听的端口号
protocol: TCP ------------------------#端口协议,支持TCP和UDP,默认TCP
targetPort: 80 -----------------------#需要转发到后端Pod的端口号
==================================================================================================
type: ClusterIP --------------------------#
ports:
- name: mnwwwp
port: 80
protocol: TCP
targetPort: 80
- name: j5smwx
port: 22
protocol: TCP
targetPort: 22
selector: -------------------------------#label selector配置,将选择具有label标签的Pod作为管理
k8s.kuboard.cn/layer: ''
k8s.kuboard.cn/name: nextcloud
sessionAffinity: None --------------------#是否支持session
7. StatefulSet.yaml
apiVersion: v1
kind: Service
metadata:
name: web01-satefulset
labels:
app: web01-satefulset
spec:
clusterIP: None
selector:
app: web01-satefulset
ports:
- port: 80
name: web
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web01-satefulset
namespace: default
spec:
serviceName: web01-satefulset
replicas: 3
selector:
matchLabels:
app: web01-satefulset
template:
metadata:
labels:
app: web01-satefulset
spec:
containers:
- name: web01-satefulset
image: nginx:1.14
ports:
- containerPort: 80