Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pod lifecycle to remove redirect iptables rule #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ different than `docker0` depending on which virtual network you use e.g.
* for [OpenShift](https://www.openshift.org/) use `tun0`
* for [Cilium](https://www.cilium.io) use `lxc+`

**Warning**: It is important ensure the iptables rule will be deleted when you delete the DaemonSet. Below is the command proposal to deal with it, we recommend to use the comand in the Pod Lifecycle:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: s/comand/command/


```bash
eval `iptables-save | grep 169.254.169.254 | sed s/-A/'iptables -t nat -D'/g`
```

```yaml
apiVersion: apps/v1
kind: DaemonSet
Expand Down Expand Up @@ -192,6 +198,12 @@ spec:
name: http
securityContext:
privileged: true
lifecycle:
preStop:
exec:
command: [
"/bin/sh", "-c", "eval `iptables-save | grep 169.254.169.254 | sed s/-A/'iptables -t nat -D'/g`"
]
```

### kubernetes annotation
Expand Down
2 changes: 2 additions & 0 deletions charts/kube2iam/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ spec:
{{- end }}
resources:
{{ toYaml .Values.resources | indent 12 }}
lifecycle:
{{ toYaml .Values.lifecycle | indent 12 }}
{{- if .Values.host.iptables }}
securityContext:
privileged: true
Expand Down
8 changes: 8 additions & 0 deletions charts/kube2iam/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ resources: {}
# cpu: 4m
# memory: 16Mi

lifecycle:
preStop:
exec:
command: [
"/bin/sh", "-c", "eval `iptables-save | grep 169.254.169.254 | sed s/-A/'iptables -t nat -D'/g`"
]


## Strategy for DaemonSet updates (requires Kubernetes 1.6+)
## Ref: https://kubernetes.io/docs/tasks/manage-daemon/update-daemon-set/
##
Expand Down
6 changes: 6 additions & 0 deletions examples/eks-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ spec:
name: http
securityContext:
privileged: true
lifecycle:
preStop:
exec:
command: [
"/bin/sh", "-c", "eval `iptables-save | grep 169.254.169.254 | sed s/-A/'iptables -t nat -D'/g`"
]
volumeMounts:
- mountPath: /run/xtables.lock
name: xtables-lock
Expand Down