はじめに¶
ステータスコード413エラーって見たことがありますか?
Nginxでは1MBを超えるクライアントからのリクエストはデフォルトで413エラーを出します. 今日はそれを人為的に起こしてみます.
やりかた¶
ConfigMapとDeployment,Serviceを起動する.
nginx-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
default.conf: |
server {
listen 80;
server_name localhost;
location /test {
limit_except POST {
deny all;
}
return 200 '{"status":"success", "message":"POST request received"}';
add_header Content-Type application/json;
}
}
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: web-container
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d
volumes:
- name: config-volume
configMap:
name: nginx-config
items:
- key: default.conf
path: default.conf
---
apiVersion: v1
kind: Service
metadata:
name: myapp
labels:
app: myapp
spec:
ports:
- name: http
port: 80
selector:
app: myapp
type: NodePort
実行する
$ kubectl apply -f nginx-configmap.yaml
$ kubectl apply -f nginx-deployment.yaml
monitoring_prometheus-operatorのログ(正常)をPOST用にダウンロードします. 0.log (1.1 MB)
Kubernetes control planeのアドレスを取得します.
$ kubectl cluster-info
Kubernetes control plane is running at https://192.168.100.203:6443
CoreDNS is running at https://192.168.100.203:6443/api/v1/namespaces/kube-system/services/rke2-coredns-rke2-coredns:udp-53/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Serviceで用いているPortを取得します.
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
myapp NodePort 10.43.85.188 <none> 80:30042/TCP 66m
/testです.
よってURLはhttps://192.168.100.203:30042/testとなります.
postcurl.sh
#bin/bash
URL=http://192.168.100.203:30042/test
FILE=0.log
INPUTNAME=upfile
echo "413"
curl -X POST $URL -F $INPUTNAME=@$FILE
echo ""
echo "status:successと出たら成功!!"
curl -X POST $URL -d 'data=example'
echo ""
$ chmod +x postcurl.sh
$ ./postcurl.sh
実行結果として,1.1MBの0.logは413エラーで失敗し,data=exampleを送信した場合は成功しています.
413
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.25.3</center>
</body>
</html>
status:successと出たら成功!!
{"status":"success", "message":"POST request received"}