【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 
相关推荐
iru5 天前
kubectl cp详解,k8s集群与本地环境文件拷贝
运维·容器·k8s
竹君子6 天前
研发管理知识库(15)K8s和Istio关系
k8s
像风一样自由202010 天前
告别“在我电脑上能跑”:Docker入门与核心概念解析
docker·容器·k8s
Garfield200513 天前
Kubeflow 运行容器时 ENTRYPOINT 被覆盖导致环境变量未生效问题分析与解决
k8s·dockerfile·kubeflow·entrypoint
南方以南_16 天前
CKA07--Argo CD
运维·kubernetes·k8s
Matana11116 天前
CentOS7 + VMware 搭建 K3s 集群遇到的网络问题全记录与解决方案
k8s
nvd1118 天前
GKE 部署 - 从`kubectl` 到 Helm Chart 的演进
k8s
虚伪的空想家19 天前
记录次etcd故障,fatal error: bus error
服务器·数据库·k8s·etcd
岚天start20 天前
KubeSphere在线安装单节点K8S集群
docker·容器·kubernetes·k8s·kubesphere·kubekey
小坏讲微服务22 天前
五分钟使用 Docker-compose搭建 Redis 8.0 中间件
运维·redis·docker·中间件·容器·kubernetes·k8s