日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

k8s 资源文件基础练习

發布時間:2025/3/21 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 k8s 资源文件基础练习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文的鏡像需自己制作

可以參考Docker進階(制作鏡像,共享卷,網絡通信,私有倉庫)_kali_yao的博客-CSDN博客??????

初始化資源文件

]# cat kubeadm-init.yaml apiVersion: kubeadm.k8s.io/v1beta2 bootstrapTokens: - groups:- system:bootstrappers:kubeadm:default-node-tokentoken: abcdef.0123456789abcdefttl: 24h0m0susages:- signing- authentication kind: InitConfiguration localAPIEndpoint:advertiseAddress: 192.168.1.21bindPort: 6443 nodeRegistration:criSocket: /var/run/dockershim.sockname: mastertaints:- effect: NoSchedulekey: node-role.kubernetes.io/master --- apiServer:timeoutForControlPlane: 4m0s apiVersion: kubeadm.k8s.io/v1beta2 certificatesDir: /etc/kubernetes/pki clusterName: kubernetes controllerManager: {} dns:type: CoreDNS etcd:local:dataDir: /var/lib/etcd imageRepository: 192.168.1.100:5000 kind: ClusterConfiguration kubernetesVersion: v1.17.6 networking:dnsDomain: cluster.localpodSubnet: 10.244.0.0/16serviceSubnet: 10.254.0.0/16 scheduler: {} --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 kind: KubeProxyConfiguration mode: ipvs

apache資源文件?

~]# vim apache-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: apache-example spec:selector:matchLabels:app: myapp-apachereplicas: 1template:metadata:labels:app: myapp-apachespec:#nodeName: node-0001containers:- name: apacheimage: 192.168.1.100:5000/myos:httpdports:- protocol: TCPcontainerPort: 80restartPolicy: Always ~]# vim httpd-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: httpd-example spec:selector:matchLabels:app: myapp-httpdreplicas: 3template:metadata:labels:app: myapp-httpdspec:containers:- name: httpdimage: 192.168.1.100:5000/myos:httpdports:- protocol: TCPcontainerPort: 80restartPolicy: Always ]# cat httpd-example-v1.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: httpd-example spec:selector:matchLabels:app: myapp-httpdreplicas: 1template:metadata:labels:app: myapp-httpdspec:containers:- name: httpdimage: 192.168.1.100:5000/myos:httpdports:- protocol: TCPcontainerPort: 80restartPolicy: Always ~]# cat httpd-example-v2.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: httpd-example spec:selector:matchLabels:app: myapp-nginxreplicas: 3revisionHistoryLimit: 10strategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:labels:app: myapp-nginxspec:containers:- name: nginximage: 192.168.1.100:5000/myos:nginxports:- protocol: TCPcontainerPort: 80restartPolicy: Always ~]# cat deployment-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: deployment-example spec:selector:matchLabels:app: myosreplicas: 1template:metadata:labels:app: myosspec:containers:- name: myosimage: 192.168.1.100:5000/myos:v1804stdin: truetty: truerestartPolicy: Always ~]# cat daemonset-example.yaml --- apiVersion: apps/v1 kind: DaemonSet metadata:name: daemonset-examplenamespace: kube-system spec:selector:matchLabels:app: myapp1template:metadata:labels:app: myapp1spec:#tolerations:#- key: "node-role.kubernetes.io/master"# operator: "Equal"# value: ""# effect: "NoSchedule"containers:- name: myosimage: 192.168.1.100:5000/myos:v1804stdin: truetty: truerestartPolicy: Always

service服務資源文件?

]# cat service-example.yaml --- apiVersion: v1 kind: Service metadata:name: apache-service spec:ports:- protocol: TCPport: 80targetPort: 80selector:app: myapachetype: ClusterIP ]# cat web-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: web-example spec:selector:matchLabels:app: myapp-webreplicas: 3#revisionHistoryLimit: 10#strategy:# rollingUpdate:# maxSurge: 25%# maxUnavailable: 25%# type: RollingUpdatetemplate:metadata:labels:app: myapp-webspec:#nodeName: node-0001#nodeSelector:# disktype: ssd#affinity:# podAffinity:# requiredDuringSchedulingIgnoredDuringExecution:# - labelSelector:# matchExpressions:# - key: app# operator: In# values:# - myapp-php# topologyKey: kubernetes.io/hostname# podAntiAffinity:# preferredDuringSchedulingIgnoredDuringExecution:# - weight: 1# podAffinityTerm:# labelSelector:# matchExpressions:# - key: app# operator: In# values:# - myapp-apache# topologyKey: kubernetes.io/hostnamecontainers:- name: nginximage: 192.168.1.100:5000/myos:nginxports:- protocol: TCPcontainerPort: 80restartPolicy: Always

pod資源文件?

~]# cat pod-example.yaml apiVersion: v1 kind: Pod metadata:name: pod-examplelabels:app: myapp spec:containers:- name: myosimage: 192.168.1.100:5000/myos:v1804stdin: truetty: truerestartPolicy: Always

?apache的service資源文件

~]# cat loadbalance.yaml --- apiVersion: v1 kind: Service metadata:name: test-service spec:selector:app: myapacheports:- protocol: TCPport: 80targetPort: 80clusterIP:externalIPs:- 192.168.1.101type: LoadBalancer

調用pv資源文件?

~]# cat configmap-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: myweb spec:selector:matchLabels:app: mywebreplicas: 1template:metadata:labels:app: mywebspec:containers:- name: php-fpmimage: 192.168.1.100:5000/myos:php-fpm- name: nginximage: 192.168.1.100:5000/myos:nginxports:- protocol: TCPcontainerPort: 80volumeMounts:- name: nginx-phpsubPath: nginx.confmountPath: /usr/local/nginx/conf/nginx.confvolumes:- name: nginx-phpconfigMap:name: nginx-conf

定時任務資源文件?

~]# cat cronjob-example.yaml --- apiVersion: batch/v1beta1 kind: CronJob metadata:name: cronjob-pi spec:schedule: "*/1 * * * *"jobTemplate:spec:template:spec:containers:- name: piimage: 192.168.1.100:5000/myos:v1804command: ["sleep", "30"]restartPolicy: OnFailure

]# cat job-example.yaml --- apiVersion: batch/v1 kind: Job metadata:name: pi spec:template:spec:containers:- name: piimage: 192.168.1.100:5000/myos:v1804command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(500)"]restartPolicy: OnFailure

pvc資源文件?

]# cat pvc-example.yaml --- apiVersion: v1 kind: PersistentVolumeClaim metadata:name: pvc-nfs spec:volumeMode: FilesystemaccessModes:- ReadWriteManyresources:requests:storage: 10Giselector:matchLabels:app: web-nfs

調用pvc資源文件?

]# cat php-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: php-example spec:selector:matchLabels:app: myapp-phpreplicas: 1template:metadata:labels:app: myapp-phpspec:#affinity:# nodeAffinity:# preferredDuringSchedulingIgnoredDuringExecution:# - weight: 1# preference:# matchExpressions:# - key: cpu# operator: In# values:# - high# requiredDuringSchedulingIgnoredDuringExecution:# nodeSelectorTerms:# - matchExpressions:# - key: mem# operator: In# values:# - high# - midcontainers:- name: php-fpmimage: 192.168.1.100:5000/myos:php-fpmports:- protocol: TCPcontainerPort: 9000restartPolicy: Always ]# cat volume-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: myweb spec:selector:matchLabels:app: mywebreplicas: 1template:metadata:labels:app: mywebspec:nodeSelector:kubernetes.io/hostname: node-0003containers:- name: myosimage: 192.168.1.100:5000/myos:v1804stdin: truetty: true#volumeMounts:#- name: web-site# mountPath: /var/www/html- name: apacheimage: 192.168.1.100:5000/myos:httpdports:- protocol: TCPcontainerPort: 80#volumeMounts:#- name: my-cache# mountPath: /var/cache#- name: my-data# mountPath: /var/www/html#volumes:#- name: my-cache# emptyDir: {}#- name: my-data# hostPath:# path: /var/webroot# type: DirectoryOrCreate#- name: web-site# persistentVolumeClaim:# claimName: pvc-nfs

pv資源文件?

]# cat pv-example.yaml apiVersion: v1 kind: PersistentVolume metadata:name: pv-nfslabels:app: web-nfs spec:volumeMode: Filesystemcapacity:storage: 10GiaccessModes:- ReadWriteManypersistentVolumeReclaimPolicy: Retainnfs:path: /var/webrootserver: 192.168.1.100

hpa資源文件?

~]# cat hpa-example.yaml --- apiVersion: apps/v1 kind: Deployment metadata:name: myweb spec:selector:matchLabels:app: apachereplicas: 1template:metadata:labels:app: apachespec:containers:- name: apacheimage: 192.168.1.100:5000/myos:httpdports:- containerPort: 80resources:requests:cpu: 200mrestartPolicy: Always--- apiVersion: v1 kind: Service metadata:name: web-service spec:ports:- protocol: TCPport: 80targetPort: 80selector:app: apachetype: ClusterIP--- apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata:name: myweb spec:minReplicas: 1maxReplicas: 3scaleTargetRef:apiVersion: apps/v1kind: Deploymentname: mywebtargetCPUUtilizationPercentage: 50

總結

以上是生活随笔為你收集整理的k8s 资源文件基础练习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。