{"id":1474,"date":"2024-12-07T07:00:22","date_gmt":"2024-12-07T07:00:22","guid":{"rendered":"https:\/\/kb.lagonet.vn\/?p=1474"},"modified":"2024-12-07T07:00:22","modified_gmt":"2024-12-07T07:00:22","slug":"huong-dan-chi-tiet-bai-lab-kubernetes-k8s-volume-persistentvolume-va-persistentvolumeclaim","status":"publish","type":"post","link":"https:\/\/kb.lagonet.vn\/?p=1474","title":{"rendered":"H\u01b0\u1edbng d\u1eabn chi ti\u1ebft b\u00e0i LAB Kubernetes (K8s): Volume, PersistentVolume v\u00e0 PersistentVolumeClaim"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>H\u01b0\u1edbng d\u1eabn chi ti\u1ebft b\u00e0i LAB Kubernetes (K8s): Volume, PersistentVolume v\u00e0 PersistentVolumeClaim<\/strong><\/h3>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Gi\u1edbi thi\u1ec7u v\u1ec1 Volume trong Kubernetes<\/strong><\/h4>\n\n\n\n<p>Kubernetes h\u1ed7 tr\u1ee3 nhi\u1ec1u lo\u1ea1i Volume, \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 l\u01b0u tr\u1eef v\u00e0 chia s\u1ebb d\u1eef li\u1ec7u gi\u1eefa c\u00e1c containers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Volume b\u00ean trong Pod<\/strong>: L\u01b0u tr\u1eef t\u1ea1m th\u1eddi (v\u00ed d\u1ee5: <code>emptyDir<\/code>), ch\u1ec9 t\u1ed3n t\u1ea1i trong v\u00f2ng \u0111\u1eddi c\u1ee7a Pod.<\/li>\n\n\n\n<li><strong>Volume trong Cluster<\/strong>: L\u01b0u tr\u1eef d\u1eef li\u1ec7u d\u00f9ng chung gi\u1eefa c\u00e1c Node trong Cluster (s\u1eed d\u1ee5ng <code>configMap<\/code>, <code>secret<\/code>, ho\u1eb7c <code>hostPath<\/code>).<\/li>\n\n\n\n<li><strong>Volume ngo\u00e0i Cluster<\/strong>: L\u01b0u tr\u1eef d\u1eef li\u1ec7u tr\u00ean NFS server, iSCSI SAN, ho\u1eb7c c\u00e1c d\u1ecbch v\u1ee5 l\u01b0u tr\u1eef \u0111\u00e1m m\u00e2y (AWS EBS, Google Cloud Storage).<\/li>\n<\/ul>\n\n\n\n<p><strong>Chi ti\u1ebft th\u00eam v\u1ec1 c\u00e1c lo\u1ea1i volume<\/strong>: <a href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/volumes\/\">Kubernetes Documentation<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. T\u1ea1o Volume trong Pod<\/strong><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 1: T\u1ea1o th\u01b0 m\u1ee5c v\u00e0 file YAML<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir volumetest &amp;&amp; cd volumetest\nnano podvolume.yaml\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>N\u1ed9i dung file <code>podvolume.yaml<\/code>:<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: Pod\nmetadata:\n  name: fortune\nspec:\n  containers:\n  - name: html-generator\n    image: luksa\/fortune\n    volumeMounts:\n    - name: html\n      mountPath: \/var\/htdocs\n  - name: web-server\n    image: nginx:alpine\n    ports:\n    - containerPort: 80\n      protocol: TCP\n    volumeMounts:\n    - name: html\n      mountPath: \/usr\/share\/nginx\/html\n      readOnly: true\n  volumes:\n  - name: html\n    emptyDir: {}\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 2: Deploy Pod<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f podvolume.yaml\nkubectl get pod -o wide\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 3: Ki\u1ec3m tra ho\u1ea1t \u0111\u1ed9ng c\u1ee7a Volume<\/strong><\/h5>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Truy c\u1eadp container <code>html-generator<\/code>:<\/strong><code>kubectl exec -it fortune -c html-generator -- \/bin\/sh<\/code>\n<ul class=\"wp-block-list\">\n<li>Ki\u1ec3m tra d\u1eef li\u1ec7u: <code>ls \/var\/htdocs touch \/var\/htdocs\/text1.txt<\/code><\/li>\n\n\n\n<li>Tho\u00e1t container: <code>exit<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Truy c\u1eadp container <code>web-server<\/code>:<\/strong><code>kubectl exec -it fortune -c web-server -- \/bin\/sh<\/code>\n<ul class=\"wp-block-list\">\n<li>Ki\u1ec3m tra file: <code>ls \/usr\/share\/nginx\/html<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. PersistentVolume (PV)<\/strong><\/h4>\n\n\n\n<p>PersistentVolume l\u00e0 kh\u00f4ng gian l\u01b0u tr\u1eef \u0111\u01b0\u1ee3c cung c\u1ea5p b\u1edfi qu\u1ea3n tr\u1ecb vi\u00ean, n\u1eb1m ngo\u00e0i Kubernetes Cluster.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 1: Thi\u1ebft l\u1eadp NFS Server<\/strong><\/h5>\n\n\n\n<p>Tr\u00ean m\u00e1y ch\u1ee7 NFS (ho\u1eb7c EC2):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install nfs-kernel-server\nsudo mkdir -p \/data\/mydata\nsudo chown -R nobody:nogroup \/data\/mydata\nsudo chmod -R 777 \/data\/mydata\n<\/code><\/pre>\n\n\n\n<p>C\u1eadp nh\u1eadt file <code>\/etc\/exports<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/exports\n<\/code><\/pre>\n\n\n\n<p>Th\u00eam d\u00f2ng:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/data\/mydata *(rw,sync,no_subtree_check,insecure)\n<\/code><\/pre>\n\n\n\n<p>Kh\u1edfi \u0111\u1ed9ng l\u1ea1i d\u1ecbch v\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nfs-kernel-server\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 2: T\u1ea1o PersistentVolume<\/strong><\/h5>\n\n\n\n<p>T\u1ea1o file <code>pv-create-nfs.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: PersistentVolume\nmetadata:\n  name: pv1\nspec:\n  storageClassName: nfsstorageclass\n  capacity:\n    storage: 3Gi\n  accessModes:\n    - ReadWriteMany\n  nfs:\n    path: \"\/data\/mydata\/\"\n    server: \"IP_CUA_NFS_SERVER\"\n<\/code><\/pre>\n\n\n\n<p>\u00c1p d\u1ee5ng file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f pv-create-nfs.yaml\nkubectl get pv\nkubectl describe pv pv1\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. PersistentVolumeClaim (PVC)<\/strong><\/h4>\n\n\n\n<p>PersistentVolumeClaim l\u00e0 y\u00eau c\u1ea7u t\u1eeb Pod \u0111\u1ec3 s\u1eed d\u1ee5ng PV.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 1: T\u1ea1o file PVC<\/strong><\/h5>\n\n\n\n<p>T\u1ea1o file <code>pvc-nfs.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  name: pvc1\nspec:\n  storageClassName: nfsstorageclass\n  accessModes:\n    - ReadWriteMany\n  resources:\n    requests:\n      storage: 3Gi\n<\/code><\/pre>\n\n\n\n<p>\u00c1p d\u1ee5ng file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f pvc-nfs.yaml\nkubectl get pvc\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. S\u1eed d\u1ee5ng PV v\u00e0 PVC trong Pod<\/strong><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 1: T\u1ea1o file Deployment<\/strong><\/h5>\n\n\n\n<p>T\u1ea1o file <code>apache-https.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: httpd\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: httpd\n  template:\n    metadata:\n      labels:\n        app: httpd\n    spec:\n      containers:\n      - name: app\n        image: httpd\n        resources:\n          limits:\n            memory: \"100Mi\"\n            cpu: \"100m\"\n        ports:\n        - containerPort: 80\n        volumeMounts:\n        - mountPath: \/usr\/local\/apache2\/htdocs\/\n          name: htdocs\n      volumes:\n      - name: htdocs\n        persistentVolumeClaim:\n          claimName: pvc1\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 2: Deploy Deployment<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f apache-https.yaml\nkubectl get pod\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>B\u01b0\u1edbc 3: Ki\u1ec3m tra<\/strong><\/h5>\n\n\n\n<p>Truy c\u1eadp Pod \u0111\u1ec3 ki\u1ec3m tra d\u1eef li\u1ec7u:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl http:\/\/&lt;POD_IP&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. T\u1ea1o Service \u0111\u1ec3 truy c\u1eadp<\/strong><\/h4>\n\n\n\n<p>\u0110\u1ec3 truy c\u1eadp Pod t\u1eeb b\u00ean ngo\u00e0i, b\u1ea1n c\u00f3 th\u1ec3 t\u1ea1o m\u1ed9t NodePort Service (file YAML).<\/p>\n\n\n\n<p>N\u1ebfu b\u1ea1n c\u1ea7n th\u00eam th\u00f4ng tin chi ti\u1ebft, h\u00e3y cho t\u00f4i bi\u1ebft!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>debugging:<\/p>\n\n\n\n<p>L\u1ed7i <code>FailedMount<\/code> v\u1edbi th\u00f4ng b\u00e1o <code>MountVolume.SetUp failed for volume \"pv1\" : mount failed: exit status 32<\/code> th\u01b0\u1eddng x\u1ea3y ra khi Kubernetes kh\u00f4ng th\u1ec3 g\u1eafn k\u1ebft (mount) PersistentVolume (PV) v\u00e0o Pod. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 c\u00e1c b\u01b0\u1edbc ki\u1ec3m tra v\u00e0 kh\u1eafc ph\u1ee5c v\u1ea5n \u0111\u1ec1 n\u00e0y:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Ki\u1ec3m tra nguy\u00ean nh\u00e2n l\u1ed7i<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>a. X\u00e1c minh c\u1ea5u h\u00ecnh PersistentVolume (PV)<\/strong><\/h4>\n\n\n\n<p>Ki\u1ec3m tra PV <code>pv1<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl describe pv pv1\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Th\u00f4ng tin c\u1ea7n ki\u1ec3m tra:<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>StorageClassName<\/code>: Ph\u1ea3i kh\u1edbp v\u1edbi PVC.<\/li>\n\n\n\n<li><code>AccessModes<\/code>: Xem c\u00f3 ph\u00f9 h\u1ee3p v\u1edbi y\u00eau c\u1ea7u c\u1ee7a Pod hay kh\u00f4ng (v\u00ed d\u1ee5: <code>ReadWriteMany<\/code>).<\/li>\n\n\n\n<li><code>NFS Path<\/code> v\u00e0 <code>NFS Server<\/code>: \u0110\u1ea3m b\u1ea3o \u0111\u00fang \u0111\u01b0\u1eddng d\u1eabn v\u00e0 IP c\u1ee7a NFS server.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>b. X\u00e1c minh c\u1ea5u h\u00ecnh PersistentVolumeClaim (PVC)<\/strong><\/h4>\n\n\n\n<p>Ki\u1ec3m tra PVC:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl describe pvc pvc1\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Th\u00f4ng tin c\u1ea7n ki\u1ec3m tra:<\/strong>\n<ul class=\"wp-block-list\">\n<li>PVC ph\u1ea3i \u1edf tr\u1ea1ng th\u00e1i <code>Bound<\/code>.<\/li>\n\n\n\n<li>PVC ph\u1ea3i s\u1eed d\u1ee5ng \u0111\u00fang StorageClass v\u00e0 PV.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Ki\u1ec3m tra k\u1ebft n\u1ed1i v\u1edbi NFS Server<\/strong><\/h3>\n\n\n\n<p>N\u1ebfu b\u1ea1n s\u1eed d\u1ee5ng NFS, Kubernetes c\u1ea7n k\u1ebft n\u1ed1i v\u1edbi NFS Server \u0111\u1ec3 mount volume.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>a. Ki\u1ec3m tra tr\u1ea1ng th\u00e1i NFS Server<\/strong><\/h4>\n\n\n\n<p>Tr\u00ean NFS Server, ki\u1ec3m tra danh s\u00e1ch c\u00e1c th\u01b0 m\u1ee5c \u0111\u01b0\u1ee3c chia s\u1ebb:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>showmount -e\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0110\u1ea3m b\u1ea3o th\u01b0 m\u1ee5c <code>\/data\/mydata<\/code> \u0111\u00e3 \u0111\u01b0\u1ee3c chia s\u1ebb.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>b. Ki\u1ec3m tra t\u1eeb Node Kubernetes<\/strong><\/h4>\n\n\n\n<p>Tr\u00ean Node Kubernetes n\u01a1i Pod \u0111\u01b0\u1ee3c l\u00ean l\u1ecbch (v\u00ed d\u1ee5: <code>worker2<\/code>), ki\u1ec3m tra kh\u1ea3 n\u0103ng mount th\u1ee7 c\u00f4ng:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install nfs-common   # N\u1ebfu ch\u01b0a c\u00e0i \u0111\u1eb7t\nsudo mount -t nfs &lt;NFS_SERVER_IP&gt;:\/data\/mydata \/mnt\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>N\u1ebfu l\u1ec7nh n\u00e0y th\u00e0nh c\u00f4ng, NFS Server ho\u1ea1t \u0111\u1ed9ng b\u00ecnh th\u01b0\u1eddng.<\/li>\n\n\n\n<li>N\u1ebfu th\u1ea5t b\u1ea1i, ki\u1ec3m tra:\n<ul class=\"wp-block-list\">\n<li>\u0110\u00fang \u0111\u1ecba ch\u1ec9 IP c\u1ee7a NFS Server (<code>&lt;NFS_SERVER_IP><\/code>).<\/li>\n\n\n\n<li>M\u1edf firewall tr\u00ean NFS Server: <code>sudo ufw allow from 0.0.0.0\/0 to any port nfs<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Ki\u1ec3m tra quy\u1ec1n tr\u00ean th\u01b0 m\u1ee5c NFS<\/strong><\/h3>\n\n\n\n<p>Tr\u00ean NFS Server, ki\u1ec3m tra quy\u1ec1n truy c\u1eadp c\u1ee7a th\u01b0 m\u1ee5c <code>\/data\/mydata<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -ld \/data\/mydata\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Quy\u1ec1n c\u1ea7n thi\u1ebft:<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>nobody:nogroup<\/code> ho\u1eb7c quy\u1ec1n <code>777<\/code> (m\u1edf r\u1ed9ng cho t\u1ea5t c\u1ea3): <code>sudo chmod 777 \/data\/mydata<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Ki\u1ec3m tra logs c\u1ee7a kubelet<\/strong><\/h3>\n\n\n\n<p>Xem logs c\u1ee7a kubelet tr\u00ean Node Kubernetes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>journalctl -u kubelet -f\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>T\u00ecm ki\u1ebfm c\u00e1c l\u1ed7i li\u00ean quan \u0111\u1ebfn g\u1eafn k\u1ebft (mount) NFS.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Ki\u1ec3m tra v\u00e0 c\u1eadp nh\u1eadt c\u1ea5u h\u00ecnh PV<\/strong><\/h3>\n\n\n\n<p>N\u1ebfu c\u1ea5u h\u00ecnh PV c\u00f3 v\u1ea5n \u0111\u1ec1, c\u1eadp nh\u1eadt file YAML v\u00e0 \u00e1p d\u1ee5ng l\u1ea1i:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: PersistentVolume\nmetadata:\n  name: pv1\nspec:\n  storageClassName: nfsstorageclass\n  capacity:\n    storage: 3Gi\n  accessModes:\n    - ReadWriteMany\n  nfs:\n    path: \"\/data\/mydata\/\"\n    server: \"&lt;NFS_SERVER_IP&gt;\"  # \u0110\u1ecba ch\u1ec9 IP c\u1ee7a NFS Server\n<\/code><\/pre>\n\n\n\n<p>\u00c1p d\u1ee5ng l\u1ea1i file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl delete pv pv1\nkubectl apply -f pv-create-nfs.yaml\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. X\u00f3a Pod v\u00e0 t\u1ea1o l\u1ea1i<\/strong><\/h3>\n\n\n\n<p>Sau khi ki\u1ec3m tra v\u00e0 kh\u1eafc ph\u1ee5c, x\u00f3a Pod <code>httpd<\/code> v\u00e0 th\u1eed t\u1ea1o l\u1ea1i:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl delete pod httpd-56d5c59999-55lsq\nkubectl apply -f apache-https.yaml\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Ki\u1ec3m tra tr\u1ea1ng th\u00e1i l\u1ea1i<\/strong><\/h3>\n\n\n\n<p>Ki\u1ec3m tra tr\u1ea1ng th\u00e1i c\u1ee7a Pod, PV v\u00e0 PVC:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods -o wide\nkubectl get pv\nkubectl get pvc\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>N\u1ebfu v\u1eabn kh\u00f4ng gi\u1ea3i quy\u1ebft \u0111\u01b0\u1ee3c, h\u00e3y cho t\u00f4i bi\u1ebft k\u1ebft qu\u1ea3 c\u1ee7a c\u00e1c l\u1ec7nh ki\u1ec3m tra tr\u00ean, \u0111\u1eb7c bi\u1ec7t l\u00e0:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Log t\u1eeb <code>kubectl describe pod<\/code>.<\/li>\n\n\n\n<li>Log c\u1ee7a <code>kubectl describe pv<\/code> v\u00e0 <code>kubectl describe pvc<\/code>.<\/li>\n\n\n\n<li>K\u1ebft qu\u1ea3 ki\u1ec3m tra k\u1ebft n\u1ed1i v\u1edbi NFS Server.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>The error indicates that Kubernetes is unable to mount the NFS volume on <code>worker2<\/code> due to missing or misconfigured NFS utilities on the node. This is a common issue and can be resolved with the following steps:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Install NFS Utilities on <code>worker2<\/code><\/strong><\/h3>\n\n\n\n<p>The NFS client tools might not be installed on the worker node. SSH into the <code>worker2<\/code> node and install the required packages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh worker2\nsudo apt update\nsudo apt install -y nfs-common\n<\/code><\/pre>\n\n\n\n<p>For CentOS\/RHEL systems:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install -y nfs-utils\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Test Manual Mounting on <code>worker2<\/code><\/strong><\/h3>\n\n\n\n<p>After installing the NFS utilities, manually test mounting the NFS share:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/mnt\/test\nsudo mount -t nfs 10.7.18.209:\/data\/mydata \/mnt\/test\nls \/mnt\/test\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If this works, unmount the directory: <code>sudo umount \/mnt\/test<\/code><\/li>\n\n\n\n<li>If it fails, check the NFS server configuration or firewall (see step 5).<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Restart Kubelet on <code>worker2<\/code><\/strong><\/h3>\n\n\n\n<p>After ensuring the NFS utilities are installed, restart the kubelet service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart kubelet\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Check and Retry Pod Creation<\/strong><\/h3>\n\n\n\n<p>Delete the stuck Pod and allow Kubernetes to recreate it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl delete pod httpd-56d5c59999-szg59 -n projectnodejs\n<\/code><\/pre>\n\n\n\n<p>Monitor the pod status as it gets recreated:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods -o wide -n projectnodejs\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Verify NFS Server Configuration<\/strong><\/h3>\n\n\n\n<p>On the NFS server (<code>10.7.18.209<\/code>):<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Ensure the directory <code>\/data\/mydata<\/code> is exported correctly: <code>showmount -e<\/code><\/li>\n\n\n\n<li>Verify the Kubernetes node (<code>worker2<\/code>) has permission to mount the share:\n<ul class=\"wp-block-list\">\n<li>Check <code>\/etc\/exports<\/code>: <code>cat \/etc\/exports<\/code> The entry should look like this: <code>\/data\/mydata *(rw,sync,no_subtree_check,insecure)<\/code><\/li>\n\n\n\n<li>If changes are made, restart the NFS service: <code>sudo exportfs -r sudo systemctl restart nfs-kernel-server<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Check firewall settings on the NFS server:\n<ul class=\"wp-block-list\">\n<li>Allow NFS traffic: <code>sudo ufw allow from &lt;worker2-IP> to any port nfs<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Check Node Logs<\/strong><\/h3>\n\n\n\n<p>If the issue persists, check the logs of the <code>worker2<\/code> node for detailed errors:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>journalctl -u kubelet -f\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Retry and Monitor<\/strong><\/h3>\n\n\n\n<p>Once the above steps are completed, retry the Pod creation and verify:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f apache-https.yaml\nkubectl get pods -o wide -n projectnodejs\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Let me know if you encounter any issues after these steps or need further assistance!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>H\u01b0\u1edbng d\u1eabn chi ti\u1ebft b\u00e0i LAB Kubernetes (K8s): Volume, PersistentVolume v\u00e0 PersistentVolumeClaim 1. Gi\u1edbi thi\u1ec7u v\u1ec1 Volume trong Kubernetes Kubernetes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[141],"tags":[],"class_list":["post-1474","post","type-post","status-publish","format-standard","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1474"}],"version-history":[{"count":1,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1474\/revisions"}],"predecessor-version":[{"id":1475,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=\/wp\/v2\/posts\/1474\/revisions\/1475"}],"wp:attachment":[{"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.lagonet.vn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}