This tool is telepresenceio/telepresence cleaner.
Using telepresence --swap-deployment
, telepresence deployment does not work if process crashes or laptop is closed. (ref: telepresenceio/telepresence#260)
Clean according to the following flow.
- Collect pods with
telepresence
labels in the specified namespace. - Check if a valid sshd process exists for those pods. If it does not exist, it is broken. (*1)
- Perform the same processing as the Telepresence Cleanup on the invalid Pods.
(*1) Broken Pod status
When telepresence is working:
~ $ ps -elf
PID USER TIME COMMAND
1 telepres 0:00 {twistd} /usr/bin/python3.6 /usr/bin/twistd --pidfile= -n -y ./forwarder.py
8 telepres 0:00 [sshd]
9 telepres 0:00 /usr/sbin/sshd -e
14 telepres 0:00 [sshd]
17 telepres 0:00 sshd: telepresence [priv]
18 telepres 0:00 sshd: telepresence [priv]
21 telepres 0:00 sshd: telepresence
22 telepres 0:00 sshd: telepresence
28 telepres 0:00 sshd: telepresence [priv]
30 telepres 0:00 sshd: telepresence@notty
31 telepres 0:00 ash -c /usr/lib/ssh/sftp-server
32 telepres 0:00 /usr/lib/ssh/sftp-server
34 telepres 0:00 sh
39 telepres 0:00 ps -elf
When telepresence is not working:
~ $ ps -elf
PID USER TIME COMMAND
1 telepres 0:00 {twistd} /usr/bin/python3.6 /usr/bin/twistd --pidfile= -n -y ./forwarder.py
8 telepres 0:00 [sshd]
9 telepres 0:00 /usr/sbin/sshd -e
14 telepres 0:00 [sshd]
21 telepres 0:00 [sshd]
22 telepres 0:00 [sshd]
30 telepres 0:00 [sshd]
31 telepres 0:00 [ash]
34 telepres 0:00 sh
43 telepres 0:00 ps -elf
telepolice sees the state of sshd process.
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: app-deployment
spec:
annotations:
telepolice/original-deployment: app-deployment
telepolice/original-deployment-replicas: 1
...
Previously, metadata.selflink of last-applied-configuration of annotations was used, but it became deprecated.
$ telepolice get
NAMESPACE STATUS POD
default true web-9bc4ceefeade40668638a0b782decec9-57f78598krqr
Broken case (STATUS = false)
$ telepolice get
NAMESPACE STATUS POD
default false web-9bc4ceefeade40668638a0b782decec9-57f78598krqr
% telepolice cleanup
Cleanup: default/web-9bc4ceefeade40668638a0b782decec9-57f78598krqr
Dry run mode by adding --dry-run
option.
$ telepolice cleanup -i 60
Start as a daemon in the foreground. Clean every 60 seconds.
$ telepolice get -n ns1,ns2
default: default
namespace
$ telepolice get -A
$ KUBECONFIG=~/.kube/other_config telepolice get
default: ~/.kube/config
$ telepolice --use-in-cluster-config get
- use master
kubectl apply -f https://raw.githubusercontent.com/takumakume/telepolice/master/manifests/release.yaml
- use tag
kubectl apply -f https://raw.githubusercontent.com/takumakume/telepolice/v0.0.1/manifests/release.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: telepolice-config
namespace: telepolice
data:
arg: "cleanup --use-in-cluster-config -A -i 30 --verbose"
edit arg
go get github.com/takumakume/telepolice