Kubernetes插件是扩展集群功能的核心工具,涵盖网络、监控、日志、可视化、CI/CD等多个场景。以下是Ubuntu环境下常用插件的具体使用步骤及注意事项:
在安装插件前,需完成Ubuntu节点的基础配置(关闭Swap、加载内核模块、安装Docker/Kubernetes组件)并初始化Master节点(kubeadm init),同时部署网络插件(如Calico)以保证Pod间通信。具体步骤可参考Kubernetes集群搭建指南。
网络插件是Kubernetes集群的“血管”,常见选项包括Calico(高性能、支持网络策略)、Flannel(简单易用):
kubectl apply -f https://docs.projectcalico.org/v3.27/manifests/calico.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get pods -n kube-system,确认网络插件相关Pod(如calico-node-xxxx、flannel-xxxx)状态为Running。监控插件帮助管理员实时掌握集群资源使用情况,常见选项包括Heapster(传统监控)、Prometheus+Grafana(现代监控方案):
kubectl apply -f https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/heapster.yaml
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/bundle.yaml
日志插件将容器日志收集、存储并可视化,常见选项包括EFK Stack(Elasticsearch+Fluentd+Kibana)、Loki+Grafana(轻量级方案):
kubectl apply -f https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/es-statefulset.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/es-service.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/fluentd-elasticsearch/kibana-deployment.yaml
helm repo add grafana https://grafana.github.io/helm-charts
helm install loki grafana/loki-stack
可视化插件提供图形化界面,方便管理员操作集群,常见选项包括Kubernetes Dashboard(官方Web UI)、Portainer(跨平台管理):
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
kubectl proxy启动代理,然后在浏览器访问http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/,通过Token认证登录。kubectl apply -f https://raw.githubusercontent.com/portainer/portainer-kubernetes/master/deploy/portainer.yaml
kubectl port-forward或Ingress暴露服务,然后在浏览器访问http://<node-ip>:9000。Jenkins Kubernetes插件实现动态Slave Pod,根据Job需求自动创建和销毁Pod,节省资源:
https://kubernetes.default.svc.cluster.local,外部用https://<K8S-IP>:6443。cluster-admin权限)。default)。maven:3.8.6-openjdk-11用于Java项目),设置容器资源限制。requests)和限制(limits),防止插件占用过多集群资源。NetworkPolicy),限制Pod间不必要的流量;监控插件(如Prometheus)需配置认证,防止未授权访问。通过以上步骤,可在Ubuntu环境的Kubernetes集群中快速部署和使用常用插件,提升集群的管理效率和功能扩展性。