使用 Kubeadm 部署 Kubernetes(K8S) 安裝
使用 Kubeadm 部署 Kubernetes(K8S) 安裝 -- Ingress-Ngnix
Volume 是 Pod 中能夠被多個容器訪問的共享目錄, Kubernetes 的 Volume 定義在 Pod 上,它被一個 Pod 中的多個容 器掛載到具體的檔案目錄下,
Volume 與 Pod 的生命周期相同,但與容器的生命周期不相關, 當容器終止或重啟時, Volume 中的資料也不會丟失, 要使用volume, pod 需要指定 volume 的型別和內容( 欄位) , 和映射到容器的位置( 欄位) ,
Kubernetes 支持多種型別的 Volume,包括: emptyDir、 hostPath、 gcePersistentDisk、awsElasticBlockStore、 nfs、 iscsi、 flocker、 glusterfs、 rbd、 cephfs、 gitRepo、secret、 persistentVolumeClaim、 downwardAPI、 azureFileVolume、 azureDisk、vsphereVolume、 Quobyte、 PortworxVolume、 ScaleIO, emptyDirEmptyDir 型別的 volume
創建于 pod 被調度到某個宿主機上的時候, 而同一個 pod 內的容器都能讀寫 EmptyDir 中的同一個檔案, 一旦這個 pod 離開了這個宿主機, EmptyDir 中的資料就會被永久洗掉, 所以目前 EmptyDir 型別的 volume 主要用作臨時空間, 比如 Web 服務器寫日志或者 tmp 檔案需要的臨時目錄
NFS 網路存府:POD 重啟,資料還存在,缺陷,需要知道NFS服務器的地址,配在 yaml中
找一臺服務器,做NFS服務端
選擇合適的節點部署,這邊使用 K8SMaster 主節點做為nfs服務器
安裝nfs
[root@k8smaster ~]# yum install -y nfs-utils
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解決依賴關系
--> 正在檢查事務
---> 軟體包 nfs-utils.x86_64.1.1.3.0-0.66.el7 將被 升級
---> 軟體包 nfs-utils.x86_64.1.1.3.0-0.68.el7.2 將被 更新
--> 解決依賴關系完成
依賴關系解決
============================================================================================================
Package 架構 版本 源 大小
============================================================================================================
正在更新:
nfs-utils x86_64 1:1.3.0-0.68.el7.2 updates 413 k
事務概要
============================================================================================================
升級 1 軟體包
總計:413 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在更新 : 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 1/2
清理 : 1:nfs-utils-1.3.0-0.66.el7.x86_64 2/2
驗證中 : 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 1/2
驗證中 : 1:nfs-utils-1.3.0-0.66.el7.x86_64 2/2
更新完畢:
nfs-utils.x86_64 1:1.3.0-0.68.el7.2
完畢!
[root@k8smaster ~]#
設定掛載路徑
# 創建nfs掛載目錄,
[root@k8smaster ~]# mkdir /nfs
# 配置掛載路徑
[root@k8smaster ~]# vi /etc/exports
#/nfs 掛載路徑 * 所有內容 (rw 讀寫權限)
/nfs *(rw,sync,no_root_squash,no_subtree_check)
[root@k8smaster ~]#
K8S node 節點安裝 nfs
k8snode1、k8snode2 都進行安裝
#節點安裝 nfs, 會自動進行掛載
[root@k8snode1 ~]# yum install -y nfs-utils
[root@k8snode1 ~]#
啟動 nfs 服務
# 啟動 nfs 服務
[root@k8smaster ~]# systemctl start nfs && systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@k8smaster ~]# ps -ef|grep nfs
root 31990 2 0 11:23 ? 00:00:00 [nfsd4_callbacks]
root 31996 2 0 11:23 ? 00:00:00 [nfsd]
root 31997 2 0 11:23 ? 00:00:00 [nfsd]
root 31998 2 0 11:23 ? 00:00:00 [nfsd]
root 31999 2 0 11:23 ? 00:00:00 [nfsd]
root 32000 2 0 11:23 ? 00:00:00 [nfsd]
root 32001 2 0 11:23 ? 00:00:00 [nfsd]
root 32002 2 0 11:23 ? 00:00:00 [nfsd]
root 32003 2 0 11:23 ? 00:00:00 [nfsd]
root 34377 29719 0 11:29 pts/0 00:00:00 grep --color=auto nfs
[root@k8smaster ~]#
部署應用驗證
nfs-ngins.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-nfs
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: wwwroot
mountPath: /usr/share/nginx/html
ports:
- containerPort: 80
volumes:
- name: wwwroot
nfs:
server: 172.16.3.181
path: /nfs
# 具休內容見上
[root@k8smaster ~]# vi nfs-nginx.yaml
[root@k8smaster ~]# kubectl apply -f nfs-nginx.yaml
deployment.apps/nginx-nfs created
[root@k8smaster ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
javademo1-d7856c75c-czv2g 1/1 Running 0 20h
javademo1-d7856c75c-n28rs 1/1 Running 0 20h
javademo1-d7856c75c-xzqjc 1/1 Running 0 20h
nginx-f89759699-5hkdw 1/1 Running 0 26d
nginx-nfs-788564fbc8-z9srr 1/1 Running 0 3m7s
# 查看內部資訊
[root@k8smaster ~]# kubectl describe pod nginx-nfs-788564fbc8-z9srr
# 進入pod 容器
[root@k8smaster ~]# kubectl exec -it nginx-nfs-788564fbc8-z9srr bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
# 查看html目錄下的內容【這時候沒內容】
root@nginx-nfs-788564fbc8-z9srr:/# ls /usr/share/nginx/html/
root@nginx-nfs-788564fbc8-z9srr:/#
# 到 nfs 服務器 創建檔案【再開一個連接命令視窗】
[root@k8smaster ~]# cd /nfs/
[root@k8smaster nfs]# vi index.html
hello nfs
# 回到容器內,再看下有沒有檔案
root@nginx-nfs-788564fbc8-z9srr:/# ls /usr/share/nginx/html/
index.html #這時候檔案就有了
root@nginx-nfs-788564fbc8-z9srr:/#
# 對外暴露 nginx-nfs 服務
[root@k8smaster nfs]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
javademo1 NodePort 10.106.43.46 <none> 8111:31452/TCP 21d
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26d
nginx NodePort 10.103.87.81 <none> 80:30339/TCP 26d
[root@k8smaster nfs]# kubectl expose deployment nginx-nfs --port=80 --type=NodePort
service/nginx-nfs exposed
[root@k8smaster nfs]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
javademo1 NodePort 10.106.43.46 <none> 8111:31452/TCP 21d
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26d
nginx NodePort 10.103.87.81 <none> 80:30339/TCP 26d
nginx-nfs NodePort 10.99.84.9 <none> 80:30205/TCP 5s
[root@k8smaster nfs]#

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/531483.html
標籤:其他
上一篇:UE代碼重構方法
