CentOSK8S的全方位闡述

一、安裝與部署

1、CentOSK8S的安裝


# 安裝kubeadm, kubelet 和 kubectl
yum install -y kubelet kubeadm kubectl

# 啟用kubelet服務並開機啟動
systemctl enable kubelet
systemctl start kubelet

2、集群部署

使用kubeadm工具,在多個節點上安裝和配置Kubernetes集群。


# 初始化master節點
kubeadm init --pod-network-cidr=10.244.0.0/16

# 安裝網路插件calico
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/etcd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/calico.yaml

# 完成後顯示kubeadm join命令,記錄下來備用
kubeadm join xxx.xxx.xxx.xxx:xxxxx --token xxxxxxxxxxxxxxxx --discovery-token-ca-cert-hash sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

二、常用命令

1、查看集群狀態


kubectl cluster-info

2、查看集群中的節點


kubectl get nodes

3、部署一個Pod


kubectl run nginx --image=nginx

4、查看部署的Pod


kubectl get pods

5、查看Pod的詳細信息


kubectl describe pod nginx

三、擴展

1、使用Helm來進行部署,管理和發現應用程序。


# 添加helm的倉庫地址
helm repo add stable https://kubernetes-charts.storage.googleapis.com/

# 下載chart
helm fetch stable/mysql

# 部署MySQL
helm install --generate-name mysql

2、自動化運維

使用Ansible自動化Kubernetes集群的部署和管理。


# 安裝ansible
yum install ansible

# 部署Kubernetes集群
ansible-playbook kubernetes.yaml

四、安全

1、使用RBAC授權。


kubectl create -f rbac.yaml

2、啟用TLS安全傳輸。


kubeadm init --control-plane-endpoint "example.com" --upload-certs --experimental-upload-certs

3、使用Kube-bench來進行安全性自檢。


# 安裝kube-bench
yum install -y kube-bench

# 運行自檢
kube-bench master

五、監控

1、使用Prometheus實現監控。


# 下載prometheus部署所需的yaml文件
wget https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/alertmanager.crd.yaml
wget https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/prometheus.crd.yaml
wget https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/prometheusrule.crd.yaml
wget https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/servicemonitor.crd.yaml

# 部署Prometheus
kubectl apply -f https://raw.githubusercontent.com/camilocot/kubernetes-prometheus-book/master/manifests/setup
kubectl apply -f https://raw.githubusercontent.com/camilocot/kubernetes-prometheus-book/master/manifests/

2、使用Grafana進行數據可視化。


# 部署grafana
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm install --generate-name stable/grafana

六、總結

通過對CentOSK8S的全方位闡述,我們了解了CentOSK8S的安裝與部署、常用命令、擴展、安全和監控。CentOSK8S是一款高效的、安全的、易於擴展和管理的容器編排工具,能夠極大地提高網站的穩定性和可靠性。

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/219755.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-09 11:00
下一篇 2024-12-09 11:00

發表回復

登錄後才能評論