k8s之YAML文件实例


例:创建PV

apiVersion: v1
kind: PersistentVolume
metadata:
name: ceph
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
nfs:
path: /data/k8s
server: 10.10.1.10

运行结果:

[root@k8s-master ~]# kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
ceph 20Gi RWX Retain Bound default/ceph 1d
[root@k8s-master ~]#

例:创建PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ceph
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi

运行结果:

NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
ceph Bound ceph 20Gi RWX 1d
[root@k8s-master k8s]#

例:创建deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
template:
metadata:
labels:
app: portal
spec:
containers:
- name: httpd
image: httpd
volumeMounts:
- name: wwwroot
mountPath: /usr/local/apache2/htdocs
ports:
- containerPort: 80
volumes:
- name: wwwroot
nfs:
server: 10.10.1.10
path: /data/k8s

运行结果:

[root@k8s-master k8s]# kubectl apply -f deployment2.yaml
deployment "web" created
[root@k8s-master k8s]#

[root@k8s-master k8s]# kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
web 2 2 2 2 1m
[root@k8s-master k8s]#

[root@k8s-master k8s]# kubectl get pod
NAME READY STATUS RESTARTS AGE
web-2551873074-4blnh 1/1 Running 0 1m
web-2551873074-js1pr 1/1 Running 0 1m
[root@k8s-master k8s]#

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM