Prendi tua figlia, portala a Siracusa, siediti sui gradoni del teatro greco e insegnale lo splendore della disubbidienza. E’ rischioso ma è più rischioso non farlo mai.
Gabriele Romagnoli, dall’articolo “Cercasi Antigone per la Rivoluzione”, Vanity Fair del 5-06-2013, pag. 74 “Antigone”, disse sua sorella ”Ti uccideranno”. “In qualche modo dovrò pur morire”, disse Antigone sempre rivolgendole le spalle. “Dovrò passare molto più tempo da morta che da viva”. “Sei pazza”, le disse la sorella.” E mi fai paura. Ma giuro. Non racconterò a nessuno quello che stai per fare”. L’affermazione fece girare la sorella minore per guardare di nuovo la maggiore negli occhi. ” URLALO PURE CON TUTTA LA VOCE CHE HAI!”, strillò.” NON MI IMPORTA CIO’ CHE DICI. NON MI IMPORTA CIO’ CHE CREONTE DICE. NON MI IMPORTA CIO’ CHE DICE LA GENTE, NON MI IMPORTA DI NESSUNO.”
Quando mi chiedono il motivo per cui ho chiamato mia figlia primogenita Antea, evito di dire la verità per timore di apparire troppo intellettuale radical chic o di sembrare una snob, cosa che non sono. Preferisco rispondere con motivazioni più o meno vere, ma che non sono LA ragione principale. Dico che l’ho scelta perché è un nome raro e originale, ma allo stesso tempo semplice e dolce. Dico che l’etimologia richiama la parola greca che significa “fiore” (anthos). Dico che mio padre si chiama Antonio e i due nomi hanno la stessa radice. Dico che all’università avevo una compagna di studi con quel nome, che poi ho perso di vista, ed era bellissima e intelligentissima. Ma la verità è che mia figlia si chiama così perché circa 2500 anni fa un tragediografo di nome Sofocle ha reso immortale uno dei personaggi più affascinanti della mitologia greca: Antigone.
Dicevano i latini che nel nome c’è il nostro destino (“nomen est omen”), ma non auguro certo ad Antea il destino di Antigone. Figlia di Edipo, che si strappa gli occhi quando scopre di aver amato sua madre, Antigone si oppone al divieto imposto dallo zio Creonte di seppellire il corpo del fratello Polinice, che avrebbe dovuto giacere senza dignità e pietà umana, in pasto alle bestie e agli uccelli predatori, poiché si era opposto al fratello Eteocle, usurpatore del trono di Tebe. La ribellione di Antigone contro una legge ingiusta, che va contro la legge naturale di dare una degna sepoltura ai morti, le costerà la vita.
Nel nome di mia figlia, così come in quello di Antigone, c’è questa parola: “anti”, questo seme di ribellione e anticonformismo che spero germogli. Come scrive Romagnoli nel suo articolo, tutte le istituzioni, a cominciare dalla famiglia, insegnano ai bambini il valore dell’obbedienza. Antigone, invece, insegna il valore della disobbedienza. L’obbedienza viene premiata, la disobbedienza viene punita. Richiede coraggio, spirito di sacrificio e idealismo. Ma è la disobbedienza a tracciare il solco per l’avanzamento della storia sulla via della giustizia e non sulla volontà di qualsiasi governante.
Ecco perché ho chiamato mia figlia Antea. Volevo che il suo nome trasmettesse, per “osmosi”, proprio queste virtù elencate da Romagnoli: il coraggio, lo spirito di sacrificio, l’idealismo. Perché Antigone è anche Ipazia, che nel IV secolo d.C. viene uccisa per difendere il suo amore per la scienza. È Malala Yousafzai, che ha rischiato la vita per affermare il diritto all’istruzione delle bambine pakistane. È Eleonora Pimentel da Fonseca, è Rosa Parks, è Dolores Ibá
We have a PHP application running with Kubernetes in pods with two dedicated containers — NGINX и PHP-FPM.
The problem is that during downscaling clients get 502 errors. E.g. when a pod is stopping, its containers can not correctly close existing connections.
So, in this post, we will take a closer look at the pods’ termination process in general, and NGINX and PHP-FPM containers in particular.
Testing will be performed on the AWS Elastic Kubernetes Service by the Yandex.Tank utility.
Для управления контейнерами на Kubernetes WorkerNodes испольузется Docker.
Pod Lifecycle — Termination of Pods
So, let’s take an overview of the pods’ stopping and termination process.
Basically, a pod is a set of processes running on a Kubernetes WorkerNode, which are stopped by standard IPC (Inter-Process Communication) signals.
To give the pod the ability to finish all its operations, a container runtime at first ties softly stop it (graceful shutdown) by sending a SIGTERM signal to a PID 1 in each container of this pod (see docker stop). Also, a cluster starts counting a grace period before force kill this pod by sending a SIGKILL signal.
The SIGTERM can be overridden by using the STOPSIGNAL in an image used to spin up a container.
Thus, the whole flow of the pod’s deleting is (actually, the part below is a kinda copy of the official documentation):
a user issues a kubectl delete pod or kubectl scale deployment command which triggers the flow and the cluster start countdown of the grace period with the default value set to the 30 second
the API server of the cluster updates the pod’s status — from the Running state, it becomes the Terminating (see Container states). A kubelet on the WorkerNode where this pod is running, receives this status update and start the pod’s termination process:
if a container(s) in the pod have a preStop hook – kubelet will run it. If the hook is still running the default 30 seconds on the grace period – another 2 seconds will be added. The grace period can be set with the terminationGracePeriodSeconds
when a preStop hook is finished, a kubelet will send a notification to the Docker runtime to stop containers related to the pod. The Docker daemon will send the SIGTERM signal to a process with the PID 1 in each container. Containers will get the signal in random order.
simultaneously with the beginning of the graceful shutdown — Kubernetes Control Plane (its kube-controller-manager) will remove the pod from the endpoints (see Kubernetes – Endpoints) and a corresponding Service will stop sending traffic to this pod
after the grace period countdown is finished, a kubelet will start force shutdown – Docker will send the SIGKILL signal to all remaining processes in all containers of the pod which can not be ignored and those process will be immediately terminated without change to correctly finish their operations
kubelet triggers deletion of the pod from the API server
API server deletes a record about this pod from the etcd
Actually, there are two issues:
the NGINX and PHP-FPM perceives the SIGTERM signal as a force как “brutal murder” and will finish their processes immediately , и завершают работу немедленно, without concern about existing connections (see Controlling nginx and php-fpm(8) – Linux man page)
the 2 and 3 steps — sending the SIGTERM and an endpoint deletion – are performed at the same time. Still, an Ingress Service will update its data about endpoints not momentarily and a pod can be killed before then an Ingress will stop sending traffic to it causing 502 error for clients as the pod can not accept new connections
$ kubectl apply -f test-deployment.yaml namespace/test-namespace created deployment.apps/test-deployment created service/test-svc created ingress.extensions/test-ingress created
Check the Ingress:
$ curl -I aadca942-testnamespace-tes-5874–698012771.us-east-2.elb.amazonaws.com HTTP/1.1 200 OK
But still, if repeat tests few times we still can get some 502 errors:
This time most likely we are facing the second issue — endpoints update is performed at the same time when the SIGTERM Is sent.
Let’s add a preStop hook with the sleep to give some time to update endpoints and our Ingress, so after the cluster will receive a request to stop a pod, a kubelet on a WorkerNode will wait for 5 seconds before sending the SIGTERM:
But it didn’t help. Not sure why as the idea seems to be correct — instead of waiting for the TERM from Kubernetes/Docker – we gracefully stopping the NGINX master process by sending QUIT.
You can also run the strace utility check which signal is really received by the NGINX.
NGINX + PHP-FPM, supervisord, and stopsignal
Our application is running in two containers in one pod, but during the debugging, I’ve also tried to use a single container with both NGINX and PHP-FPM, for example, trafex/alpine-nginx-php7.
There I’ve tried to add to stopsignal to the supervisor.conf for both NGINX and PHP-FPM with the QUIT value, but this also didn’t help although the idea also seems to be correct.
Also, it can be a good idea to use the [Connection: close] header – then the client will close its connection right after a request is finished and this can decrease 502 errors count.
But anyway they will persist if NGINX will get the SIGTERM during processing a request.
“Oggi è stata una giornata difficile”, disse Pooh. Ci fu una pausa. “Vuoi parlarne?” chiese Pimpi. “No” disse Pooh dopo un po’. “No, non credo”. “Va bene”, disse Pimpi, e si sedette accanto al suo amico. “Cosa stai facendo?” chiese Pooh. “Niente” disse Pimpi. “Solo, so come sono i giorni difficili. Molto spesso non va di parlare neanche a me nei miei giorni difficili”. “Ma…” continuò Pimpi, “i giorni difficili sono molto più facili quando sai di avere qualcuno lì per te. E io sarò sempre qui per te, Pooh.” E mentre Pooh sedeva lì, rimuginando sulle difficoltà della giornata, mentre Pimpi sedeva accanto a lui in silenzio, facendo oscillare le sue piccole gambe… pensava che il suo migliore amico aveva proprio ragione
Install a custom Kubernetes cluster with Rancher. Use the ‘Custom’ cluster.
Add Kubernetes nodes and join the Kubernetes cluster
Run the following commands on all the VMs that your Kubernetes cluster will run on. The final docker command will have the VM join the new Kubernetes cluster.
Replace the –server and –token with your Rancher server and cluster token.
kubectl patch storageclass fast -p ‘{“metadata”: {“annotations”:{“storageclass.kubernetes.io/is-default-class”:”true”}}}’
Using the default Nginx Igress
Rancher automatically installs the nginx ingress controller on all the nodes in the cluster. If you are able to expose one of the VMs in the cluster to the outside world with a public IP then you can connect to the ingress based services on ports 80 and 443.
Any app you want to be accessible through the default nginx ingress must be added to the ‘default’ project in Rancher.
Ti stai sbagliando non è stata una coincidenza..ognuno di noi si trova dov’è per via delle scelte che ha compiuto! Che fossimo in classe insieme non è stato un caso..non è stato nemmeno a causa del destino..Per scrivere “Vivere con la morte” ho scelto quel quaderno..a te che piacciono i libri ha incuriosito e l’hai raccolto..e poi hai accettato il mio desiderio..Tutte le scelte che hai fatto finora..tutte le scelte che io ho fatto finora..ogni nostra scelta si è accumulata alle altre e ci ha fatto incontrare! Ecco perché siamo qui ora..
Mio padre mi ha detto che si da piccolo ero molto sensibile, come Simone. Mi ha detto che da piccolo piangevo ogni volta che vedevo il brutto anatrocco.