Skip to content

Commit

Permalink
Merge pull request #1 from tcarmet/first-setup
Browse files Browse the repository at this point in the history
First commit
  • Loading branch information
Thomas Carmet committed Feb 13, 2019
2 parents f7f8c2a + 672ff37 commit abc0f27
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*~
*.log
55 changes: 55 additions & 0 deletions README.md
@@ -1,2 +1,57 @@
# k8s-connection-reset
Sharing code to reproduce an issue with Kubernetes

## Requisites
To install the following code you'll need

* A kubernetes cluster.
* `kubectl`.

## Install steps to reproduce the issue

### Deploying with skaffold

If you have [skaffold](https://github.com/GoogleContainerTools/skaffold)
installed.

```bash
$ skaffold run
# or
$ skaffold dev
```

### Deploying with kubectl

```bash
$ kubectl apply -f kube
```

## :warning: Important note :warning:

Some of the clients pod must be scheduled on a different node
(it can be just one different node) to reproduce the issue.

We identified that when everything was scheduled on only one node the
problem was harder to reproduce.

## Identifying the issue

Check on Stackdriver logging the log from the server and client.
on the search bar you can set `text:'reset by peer'` and you'll see the
following errors:

```bash
# Error reported by the server
E [info] 11#11: *21885 client 10.20.6.249 closed keepalive connection (104: Connection reset by peer)
# Error reported by the client
E curl: (56) Recv failure: Connection reset by peer
```

Both line should follow each other. If the client and the server are not
reporting at the same time a `Connection reset by peer` you can ignore the
event as it might be something else.

## Troubleshooting

If the clients seem stuck feel free to restart the pods like the following
`kubectl delete pod -l app=client`
16 changes: 16 additions & 0 deletions kube/client-configmap.yaml
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: client-script
data:
client.sh: |
#!/bin/sh
# $1 file url
# waiting for the server to be available
sleep 10
while true; do
curl -o file.txt $1
done
36 changes: 36 additions & 0 deletions kube/connrst-client-deployment.yaml
@@ -0,0 +1,36 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: client
labels:
app: client
spec:
replicas: 10
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
spec:
containers:
- name: client-connection-reset
image: byrnedo/alpine-curl:0.1.7
imagePullPolicy: "IfNotPresent"
command: ['/bin/sh', '-c']
args: ['/client.sh http://nginx/small-file.txt']
volumeMounts:
- name: workspace
mountPath: /tmp
- name: client-script
mountPath: /client.sh
subPath: client.sh
volumes:
- name: workspace
emptyDir:
- name: client-script
configMap:
name: client-script
defaultMode: 0755
50 changes: 50 additions & 0 deletions kube/connrst-server-deployment.yaml
@@ -0,0 +1,50 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
initContainers:
- name: create-content
image: alpine
command: ['/bin/sh', '-c']
args: ['dd if=/dev/urandom of=/data/small-file.txt bs=1M count=4']
volumeMounts:
- name: workspace
mountPath: /data
containers:
- name: nginx
image: nginx:1.15.1-alpine
imagePullPolicy: "IfNotPresent"
ports:
- name: http
containerPort: 80
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: "1"
memory: 1Gi
volumeMounts:
- name: workspace
mountPath: /data
- name: config-nginx
mountPath: /etc/nginx/conf.d/
volumes:
- name: workspace
emptyDir:
- name: config-nginx
configMap:
name: config-nginx
16 changes: 16 additions & 0 deletions kube/connrst-server-service.yaml
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
sessionAffinity: ClientIP
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
selector:
app: nginx
16 changes: 16 additions & 0 deletions kube/nginx-configmap.yaml
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: config-nginx
data:
default.conf: |
server {
listen 80 default_server;
listen [::]:80 default_server;
error_log /var/log/nginx/error.log debug;
server_name localhost;
location / {
root /data;
}
}
7 changes: 7 additions & 0 deletions skaffold.yaml
@@ -0,0 +1,7 @@
apiVersion: skaffold/v1beta4
kind: Config
build:
deploy:
kubectl:
manifests:
- kube/*.yaml

0 comments on commit abc0f27

Please sign in to comment.