K8S中的ingress怎么取消显示版本号,不使用configmap
时间: 2024-03-17 22:41:55 浏览: 54
如果您不想使用ConfigMap来修改Nginx配置文件,可以在Ingress Controller的启动参数中添加`-nginx-http-server-tokens=""`选项来禁用Nginx版本号的显示。具体步骤如下:
1. 修改Ingress Controller的启动命令,在其中添加`-nginx-http-server-tokens=""`选项。例如,可以使用以下命令启动Ingress Controller:
```
kubectl create deployment nginx-ingress --image=nginx/nginx-ingress:latest --command -- /nginx-ingress-controller --nginx-http-server-tokens=""
```
这将在容器中启动Nginx Ingress Controller,并将`-nginx-http-server-tokens`选项设置为空字符串。
2. 部署Ingress资源,并验证HTTP响应头中不再显示Nginx版本号。
这样,就可以在不使用ConfigMap的情况下,禁用Nginx版本号的显示。
相关问题
K8S启动ingress不显示版本号,且不使用configmap
要在启动Ingress Controller时禁用Nginx版本号的显示,可以通过在命令行中添加`-nginx-http-server-tokens=""`选项来实现。具体步骤如下:
1. 创建一个Deployment来部署Ingress Controller。例如,可以使用以下命令创建Deployment:
```
kubectl create deployment nginx-ingress --image=nginx/nginx-ingress:latest --command -- /nginx-ingress-controller --nginx-http-server-tokens=""
```
这将启动一个名为nginx-ingress的Deployment,使用最新版本的Nginx Ingress Controller镜像,并将`-nginx-http-server-tokens`选项设置为空字符串。
2. 创建一个Service,将Ingress Controller暴露为ClusterIP。例如,可以使用以下命令创建Service:
```
kubectl expose deployment nginx-ingress --port=80 --target-port=80 --type=ClusterIP
```
这将创建一个名为nginx-ingress的Service,将Ingress Controller的80端口暴露为ClusterIP类型的服务。
3. 部署Ingress资源,并验证HTTP响应头中不再显示Nginx版本号。
这样,就可以在不使用ConfigMap的情况下,禁用Nginx版本号的显示。
K8S中的ingress怎么取消显示版本号
在Kubernetes中取消显示版本号,需要在Ingress资源中添加以下注释:
```
metadata:
annotations:
nginx.ingress.kubernetes.io/server-snippet: |
server_tokens off;
```
这样就可以取消显示版本号了。具体来说,这个注释会在Nginx配置文件中添加一行代码,将服务器的版本号隐藏起来。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)