已解决:k8s集群启动后,默认创建哪些namespace?

1、k8s集群启动后会创建如下namespace

[root@master ~]# kubectl  get namespace
NAME              STATUS   AGE
default           Active   45h     #  所有未指定Namespace的对象都会被分配在default命名空间
kube-node-lease   Active   45h     #  集群节点之间的心跳维护,v1.13开始引入
kube-public       Active   45h     #  此命名空间下的资源可以被所有人访问(包括未认证用户)
kube-system       Active   45h     #  所有由Kubernetes系统创建的资源都处于这个命名空间

PS:namespace可以简写成ns

2、每个namespace中都运行了特定的pod

其中kube-system这个空间有7组pod,每组pod的作用如下:

### 配置和部署 Prometheus 监控系统的指南 #### 准备工作 为了在 Kubernetes 集群中成功部署 Prometheus,需确保已安装 `kubectl` 并配置好集群访问权限。此外,建议使用 Helm 或 Operator 来简化部署过程。 --- #### 使用 Helm 安装 Prometheus Helm 是一种流行的 Kubernetes 包管理工具,可以快速完成 Prometheus 的安装与配置。 运行以下命令来添加 Prometheus 社区的 Chart 仓库并更新本地缓存: ```bash helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update ``` 通过以下命令安装 Prometheus 到名为 `monitoring` 的命名空间中: ```bash helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespace ``` 此操作会自动创建必要的资源对象,如 ServiceMonitor、Prometheus 实例以及 Grafana 可视化平台[^1]。 --- #### 手动方式部署 Prometheus 如果不想依赖 Helm,则可以通过 YAML 文件手动定义各组件: 1. **创建 Namespace** 创建一个专门用于存储监控相关资源的命名空间。 ```yaml apiVersion: v1 kind: Namespace metadata: name: monitoring ``` 2. **应用 RBAC 资源** 确保 Prometheus 拥有读取所需指标数据的权限。 ```yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: prometheus-clusterrolebinding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: prometheus subjects: - kind: ServiceAccount name: default namespace: monitoring ``` 3. **启动 Prometheus Pod** 下面是一个简单的 Prometheus Deployment 和 Service 示例: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: prometheus-deployment namespace: monitoring spec: replicas: 1 selector: matchLabels: app: prometheus template: metadata: labels: app: prometheus spec: containers: - name: prometheus image: prom/prometheus:v2.30.3 args: - "--config.file=/etc/prometheus/prometheus.yml" - "--storage.tsdb.path=/prometheus/" ports: - containerPort: 9090 volumeMounts: - name: config-volume mountPath: /etc/prometheus/ - name: storage-volume mountPath: /prometheus/ volumes: - name: config-volume configMap: name: prometheus-config - name: storage-volume emptyDir: {} --- apiVersion: v1 kind: ConfigMap metadata: name: prometheus-config namespace: monitoring data: prometheus.yml: | global: scrape_interval: 15s scrape_configs: - job_name: 'kubernetes-nodes' kubernetes_sd_configs: - role: node --- apiVersion: v1 kind: Service metadata: name: prometheus-service namespace: monitoring spec: type: NodePort ports: - port: 9090 targetPort: 9090 selector: app: prometheus ``` 4. **验证服务状态** 运行以下命令确认 Prometheus 是否正常运行: ```bash kubectl get pods,svc --namespace=monitoring ``` --- #### 访问 Prometheus Web 界面 一旦 Prometheus 成功部署,可通过浏览器查看其控制台页面。假设选择了 `NodePort` 类型的服务暴露模式,默认端口为 `9090`,则可输入如下地址访问: ``` http://<任意节点IP>:<分配给Service的外部端口号>/ ``` 此时应该能够看到 coredns 和 kube-apiserver 已被纳入监控范围内的消息[^2]。 --- #### 整合 Alertmanager 提供告警功能 除了基本的数据采集外,还可以进一步扩展设置报警规则并通过邮件或其他渠道发送通知提醒管理员注意潜在问题的发生情况。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

魏波.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值