In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Why can't k8s pv and PVC be bound?
Using statefuset to deploy stateful applications, applications are always in pending state. Before starting, introduce what is statefuset. In K8s, deployment is generally used to manage stateless applications. Statefuset is used to manage stateful applications, such as redis, mysql, zookper and other distributed applications. These applications will be started and stopped in a strict order.
1. Statefulset
Headless (headless service), without cluserIP, resource identifier, used to generate parsable dns records
StatefulSet is used to manage pod resources
VolumeClaimTemplates provides storage
II. Statefulset deployment
Using nfs for Network Storage
Set up nfs
Configure shared storage directory
Create pv
Choreographed yaml
Set up nfs
Yum install nfs-utils-y
Mkdir-p / usr/local/k8s/redis/pv {7.. 12} # create a mount directory
Cat / etc/exports / usr/local/k8s/redis/pv7 172.16.0 rw,sync,no_root_squash 16 (rw,sync,no_root_squash) / usr/local/k8s/redis/pv8 172.16.0 Universe 16 (rw,sync,no_root_squash) / usr/local/k8s/redis/pv9 172.16.0 Universe 16 (rw,sync,no_root_squash) / usr/local/k8s/redis/pv10 172.16.0.0 Universe 16 (rw,sync) No_root_squash) / usr/local/k8s/redis/pv11 172.16.0.0 no_root_squash 16 (rw,sync,no_root_squash exportfs-avr)
Create pv
Cat nfs_pv2.yaml
ApiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv7spec: capacity: storage: 500m accessModes:-ReadWriteMany persistentVolumeReclaimPolicy: Retain storageClassName: slow nfs: server: 172.16.0.59 path: "/ usr/local/k8s/redis/pv7"-apiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv8spec: capacity: storage: 500m accessModes:-ReadWriteMany storageClassName: slow persistentVolumeReclaimPolicy: Retain nfs: server: 172.16.0.59 path: "/ usr/local / k8s/redis/pv8 "--apiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv9spec: capacity: storage: 500m accessModes:-ReadWriteMany storageClassName: slow persistentVolumeReclaimPolicy: Retain nfs: server: 172.16.0.59 path:" / usr/local/k8s/redis/pv9 "--apiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv10spec: capacity: storage: 500m accessModes:-ReadWriteMany storageClassName: slow persistentVolumeReclaimPolicy: Retain nfs: server: 172.16.0. 59 path: "/ usr/local/k8s/redis/pv10"-apiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv11spec: capacity: storage: 500m accessModes:-ReadWriteMany storageClassName: slow persistentVolumeReclaimPolicy: Retain nfs: server: 172.16.0.59 path: "/ usr/local/k8s/redis/pv11"-- apiVersion: v1kind: PersistentVolumemetadata: name: nfs-pv12spec: capacity: storage: 500m accessModes:-ReadWriteMany storageClassName: slow persistentVolumeReclaimPolicy: Retain nfs: Server: 172.16.0.59 path: "/ usr/local/k8s/redis/pv12"
Kubectl apply-f nfs_pv2.yaml
View # created successfully
Write yaml choreography application
ApiVersion: v1kind: Servicemetadata: name: myapp labels: app: myappspec: ports:-port: 80 name: web clusterIP: None selector: app: myapp-pod---apiVersion: apps/v1kind: StatefulSetmetadata: name: myappspec: serviceName: myapp replicas: 3 selector: matchLabels: app: myapp-pod template: metadata: labels: app: myapp-pod spec: containers:-name: myapp image: ikubernetes / myapp:v1 resources: requests: cpu: "500m" memory: "500Mi" ports:-containerPort: 80 name: web volumeMounts:-name: myappdata mountPath: / usr/share/nginx/html volumeClaimTemplates:-metadata: name: myappdata spec: accessModes: ["ReadWriteOnce"] storageClassName: "slow" resources: requests: storage: 400Mi
Kubectl create-f new-stateful.yaml
Check whether the headless is created successfully
Check whether the pod is created successfully
Check whether the pvc is created successfully
Pod startup is not successful, depends on pvc, check the log of pvc, did not find the corresponding pvc, obviously wrote ah
To view the associated information, there is the following property
StorageClassName: "slow"
III. Statefulset troubleshooting
Pvc could not be created, so pod could not start properly, and the yaml file was rechecked several times.
Direction of thinking: how pvc binds pv, disassociates through storageClassName, pv is also created successfully, and there is also the attribute storageClassName: slow, but I can't find it.
.
.
Later, check whether the permissions of pv and pvc have been
Discover permissions set by pv
VolumeClaimTemplates: declared pvc permissions
The permissions of both sides are not the same.
Operation
Delete pvc kubectl delete pvc myappdata-myapp-0-n daemon
Delete the yaml file, kubectl delete-f new-stateful.yaml-n daemon
Try to modify accessModes: ["ReadWriteMany"]
Check again
Tip: pv and PVC set permission notes
4. Statefulset testing and domain name resolution
Kubectl exec-it myapp-0 sh-n daemon
Nslookup myapp-0.myapp.daemon.svc.cluster.local
The rules for parsing are as follows
Myapp-0 myapp daemon
FQDN: $(podname). (headless server name). Namespace.svc.cluster.local
If there is no nsllokup in the container, you need to install the corresponding package. Busybox can provide similar functions.
Provide yaml files
ApiVersion: v1kind: Podmetadata: name: busybox namespace: daemonspec: containers:-name: busybox image: busybox:1.28.4 command:-sleep-"7600" resources: requests: memory: "200Mi" cpu: "250m" imagePullPolicy: IfNotPresent restartPolicy: Never
5. Expansion and reduction of statefulset
Capacity expansion:
The expansion and reduction of Statefulset resources is similar to that of Deployment resources, that is, by modifying the number of copies, the expansion process of Statefulset resources is similar to the creation process, and the index number of the application name is increased in turn.
You can use kubectl scale
Kubectl patch
Practice: kubectl scale statefulset myapp-replicas=4
Scale down:
Downsizing only needs to reduce the number of pod copies.
Kubectl patch statefulset myapp-p'{"spec": {"replicas": 3}'- n daemon
Tip: to expand and scale up resources, you need to dynamically create a binding relationship between pv and pvc. Here, nfs is used for persistent storage, and how much of pv is created in advance.
VI. Rolling updates of statefulset
Scrolling update
Canary release
Scrolling update
Rolling update starts with the largest index pod number, terminates one resource and starts the next pod. Rolling update is the default update policy of statefulset.
Kubectl set image statefulset/myapp myapp=ikubernetes/myapp:v2-n daemon
Upgrade process
View pod status
Kubectl get pods-n daemon
Check whether the image is updated after the upgrade
Kubectl describe pod myapp-0-n daemon
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.