Kubernetes(K8s)
什么是Kubernetes?
- 為
容器化應用提供集群部署和管理的開源工具,由Google研發,在2014開源, Pod:一個pod可以運行多個容器,
Kubernetes 安裝
# 前提 安裝 docker
# 配置K8s安裝源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
# 臨時關閉 selinux
setenforce 0
# 安裝
yum install -y kubelet kubeadm kubectl
# 由于官網未開放同步方式, 可能會有索引gpg檢查失敗的情況, 這時請用以下安裝命令
yum install -y --nogpgcheck kubelet kubeadm kubectl
#配置開機自啟
systemctl enable kubelet && systemctl start kubelet
# 初始化時錯誤
[ERROR CRI]: container runtime is not running: output: E0910 18:37:12.496739 2884 remote_runtime.go:925]
"Status from runtime service failed" err="rpc error: code = Unimplemented desc =unknown service runtime.v1alpha2.RuntimeService"
# 解決
# 1)查看容器配置:CRI、是否被禁用
cat /etc/containerd/config.toml
# 2)移除
rm -fr /etc/containerd/config.toml
# 3)重啟容器
systemctl restart containerd
# 4)查看容器狀態
systemctl status containerd.service
# 初始化時錯誤:
Unfortunately, an error has occurred:
timed out waiting for the condition
This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
- 'systemctl status kubelet'
- 'journalctl -xeu kubelet'
Additionally, a control plane component may have crashed or exited when started by the container runtime.
To troubleshoot, list all containers using your preferred container runtimes CLI.
Here is one example how you may list all running Kubernetes containers by using crictl:
- 'crictl --runtime-endpoint unix:///var/run/containerd/containerd.sock ps -a | grep kube | grep -v pause'
Once you have found the failing container, you can inspect its logs with:
- 'crictl --runtime-endpoint unix:///var/run/containerd/containerd.sock logs CONTAINERID'
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher
# 解決方案
# 1) 配置docker
cat <<EOF > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors":["https://ud6340vz.mirror.aliyuncs.com"]
}
EOF
# 2) 重啟生效 : docker
systemctl daemon-reload
systemctl restart docker
# 3) 重置配置 : kubeadm
kubeadm reset
kubeadm init \
--image-repository=registry.aliyuncs.com/google_containers \
--config /etc/kubernetes/kubeadm-config.yaml
kubeadm init phase preflight --config /etc/kubernetes/kubeadm-config.yaml
hostnamectl set-hostname node1
Kubenetes 組件
kubelet
- 運行在
cluster所有節點上,負責啟動POD和容器,
kubeadm
- 用于初始化
cluster
kubectl
Kubenetes命令列工具,部署和應用,查看各種資源、創建、洗掉和更新組件,
Ingress
- 統一路由
常用命令
# Master --》 Servcie --》 deployment --》 pod --》 容器(Docker)
# 命令空間
kubectl create namespace bpg-dev
kubectl delete namespace bpg-dev
# 查看節點
kubectl get nodes
kubectl get cm -n bpg-uat
kubectl get cm -owide -n bpg-uat -owide
kubectl get svc,pod -owide -n bpg-uat
# 容器
kubectl create
kubectl get service #查看
kubectl delete service soul-nginx # 洗掉
# 控制器
kubectl create deployment soul-nginx # 創建
kubectl apply -f deployment.yml
kubectl get deployment/deploy # 查看
kubectl delete deployment/deploy soul-nginx # 洗掉
# pod
kubectl apply -f ./auth-frontend/deployment.yml # 創建pod
kubectl get pods # 查看所有的pod
kubectl get pods -n bpg-dev # 命令空間篩選
kubectl describe pod soul-nginx-d4b56f745-vljz9 -n bpg-uat # 查看pod詳細資訊
kubectl delete pod soul-nginx-d4b56f745-vljz9 # 洗掉pod
# 配置
kubectl get configmaps -n uat-bpg
kubectl describe configmaps bpg-config
kubectl create -f tpi-web-config.yml
# 日志
# 以檔案方式輸出
kubectl logs --since=3h ip-emr-web-deployment-b55944f98-848w9 -n bpg > ip-emr-20221128.log
kubectl logs --since-time="2022-12-09T22:00:00+00:00" ip-emr-web-deployment-854c8686dc-vb5k6 -n bpg > ip-emr-20221128.log
Kubenetes 應用
Nginx
# 部署
kubectl create deployment soul-nginx --image=nginx
# 暴露控制器埠
kubectl expose deployment soul-nginx --port=80 --type=NodePOrt
# 查看
kubectl get svc,pod
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/554589.html
標籤:其他
上一篇:5.1 檔案操作(讀寫、追加等)
下一篇:返回列表
