【CKS最新模拟真题】Apiserver 安全

系列文章目录

【CKS最新模拟真题】获取多个集群的上下文名称并保存到指定文件中
【CKS最新模拟真题】Falco 的运行时安全性


文章目录


一、TASK

题目要求

Solve this question on: ssh cks7262

You received a list from the DevSecOps team which performed a security investigation of the cluster. The list states the following about the apiserver setup:

Accessible through a NodePort Service

Change the apiserver setup so that:

Only accessible through a ClusterIP Service

中译

在以下位置解决此问题:ssh cks7262

您收到了 DevSecOps 团队发送的列表,该团队对集群执行了安全调查。该列表说明了 apiserver 设置的以下内容:
1、可通过 NodePort 服务访问
2、更改 apiserver 设置,以便:

只能通过 ClusterIP 服务访问

二、问题解决过程

1、问题一解题

过程如下(示例):

shell 复制代码
#首先通过 ssh 进入 controlplane 节点,并检查 apiserver 进程正在使用哪些参数运行
#按要求连接对应的集群
candidate@terminal:~$ ssh cks7262

#切换到root用户下,防止普通用户操作写入文件没权限
candidate@cks7262:~$  sudo -i
root@cks7262:~# ps -ef |grep apiserver 
关注到这个 --kubernetes-service-node-port=31000

#检查 Service 并查看它的 NodePort 类型
root@cks7262:~# kubectl get svc
NAME         TYPE       CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
kubernetes   NodePort   10.96.0.1    <none>        443:31000/TCP   5d2h

#编辑apiserver.yml清单文件删除不安全的设置
root@cks7262:~# vim /etc/kubernetes/manifests/kube-apiserver.yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 192.168.100.11:6443
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
    ...
    - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
#    - --kubernetes-service-node-port=31000   # delete or set to 0
    - --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
    - --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
	...

#等待apiserver启动完成
root@cks7262:~# watch crictl ps

2、问题二解题

过程如下(示例):

shell 复制代码
#删除默认的svc,会自动创建新的svc,类型为clusterIP
root@cks7262:~# kubectl delete svc kubernetes 
相关推荐
万里侯1 天前
GitOps 2026年演进趋势:从配置管理到环境即代码的范式转移及Pull vs Push模型的再思考
微服务·容器·k8s
张洛闻Eren5 天前
云原生k8s【第一课】: Docker 容器技术
运维·云原生·容器·k8s
KeepSeek9 天前
AI集群搭建k8s实战(docker)
k8s
要开心吖ZSH10 天前
测试环境 K8s 502 故障复盘:被 ClusterIP 表象误导,最终定位 kube-proxy 规则缺失
云原生·容器·kubernetes·k8s·502 bad gateway·kube-proxy
m0_5257247212 天前
Jenkins共享库实现流水线复用
自动化·k8s·devops
菜地里的小菜鸟18 天前
failed to get imageFs info: non-existent label “docker-images
k8s·failedtogetimagefsin·k8s报错
菜地里的小菜鸟20 天前
kubectl debug
k8s·kubectldebug
腾飞开源22 天前
01_K8s干货笔记之认识K8s
运维·笔记·云原生·容器·kubernetes·k8s·容器化部署
小匠石钧知25 天前
02_在多个RockyLinux10虚拟机上安装k8s集群
云原生·容器·kubernetes·k8s
ShirleyWang0121 个月前
让headlamp控制台能访问
linux·服务器·python·k8s·k3s