利用之前创建的storageclass,部署了个statefulset. 如下为yaml文件
[root@master ~]# cat nginx-statefulset.yaml
apiVersion: v1kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 3 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: 192.168.122.1:5000/nginx:latest
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: liping-ceph-fast
resources:
requests:
storage: 1Gi
创建完毕,集群创建了三个pod.pod名字为statefulset的名字和顺序号组成,pod也以此顺序号依次创建.
创建了三个pV并绑定到pod上面
pod运行的node节点查看rbd的map状态.
参考:
https://v1-8.docs.kubernetes.io/docs/concepts/workloads/controllers/statefulset/