【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 
相关推荐
一个天蝎座 白勺 程序猿13 小时前
Python爬虫(29)Python爬虫高阶:动态页面处理与云原生部署全链路实践(Selenium、Scrapy、K8s)
redis·爬虫·python·selenium·scrapy·云原生·k8s
格桑阿sir6 天前
Kubernetes控制平面组件:Kubelet 之 Static 静态 Pod
kubernetes·k8s·kubelet·static pod·静态pod·mirror pod·镜像pod
牛奔7 天前
Ubuntu20.04 搭建Kubernetes 1.28版本集群
k8s
matrixlzp11 天前
K8S 基于本地存储的持久卷
云原生·容器·kubernetes·k8s
matrixlzp12 天前
K8S PV 与 PVC 快速开始、入门实战
云原生·容器·kubernetes·k8s
A尘埃13 天前
K8S的使用(部署pod\service)+安装kubesphere图形化界面使用和操作
k8s·kubesphere
matrixlzp14 天前
K8S ConfigMap 快速开始
k8s
yuanlaile20 天前
Go全栈_Golang、Gin实战、Gorm实战、Go_Socket、Redis、Elasticsearch、微服务、K8s、RabbitMQ全家桶
linux·redis·golang·k8s·rabbitmq·gin
人生偌只如初见21 天前
Kubernetes学习笔记-配置Service对接第三方访问
kubernetes·k8s
梁萌22 天前
14-DevOps-快速部署Kubernetes
运维·kubernetes·k8s·devops·kubeode