<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gleb Stepanov on Medium]]></title>
        <description><![CDATA[Stories by Gleb Stepanov on Medium]]></description>
        <link>https://medium.com/@glebstepanov1992?source=rss-60f06e874747------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7l0vTa5DSLncdA7U.</url>
            <title>Stories by Gleb Stepanov on Medium</title>
            <link>https://medium.com/@glebstepanov1992?source=rss-60f06e874747------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 20:26:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@glebstepanov1992/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Synctest package for discrete event simulation:]]></title>
            <link>https://medium.com/@glebstepanov1992/synctest-package-for-discrete-event-simulation-463a07eda814?source=rss-60f06e874747------2</link>
            <guid isPermaLink="false">https://medium.com/p/463a07eda814</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[synctest]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Gleb Stepanov]]></dc:creator>
            <pubDate>Fri, 07 Nov 2025 14:07:50 GMT</pubDate>
            <atom:updated>2025-11-07T14:07:50.522Z</atom:updated>
            <content:encoded><![CDATA[<p>In Go 1.24, a new experimental package testing/synctest was introduced.<br> To use it in Go 1.24, you need to compile your code with:</p><pre>GOEXPERIMENT=synctest</pre><p>Let’s imagine we want to model some physical process — for example, billiard balls randomly rolling around a billiard table.<br> We know the speed and direction of each ball, and we want to simulate how the system evolves over time.</p><p>A simple approach would be to move every ball forward by small time steps (e.g., every 10 ms) and check if any collisions occur.<br> This method is straightforward but highly inefficient.</p><p>An alternative approach is called <strong>discrete-event simulation (DES)</strong>.<br> Instead of updating the system incrementally, we jump directly to the points in time where the system’s state changes (collisions).<br> We predict when the next collision will happen, move the simulation time to that point, and then calculate the next event again.</p><p>The same idea is applied in the testing/synctest package.<br> During a test, the standard timer is virtualized, creating a so-called “time bubble” where time can be controlled deterministically:</p><pre>func TestAfterFunc(t *testing.T) {<br>    synctest.Run(func() {<br>        ...<br>        // Timer is patched here.<br>        ...<br>    })<br>}</pre><p>Simple example showing that test finishes instantly instead of waiting 10 and 20s.</p><pre>func TestTime(t *testing.T) {<br>    synctest.Test(t, func(t *testing.T) {<br>       start := time.Now() // always midnight UTC 2000-01-01<br>       go func() {<br>          time.Sleep(10 * time.Second)<br>          t.Log(time.Since(start)) // always logs &quot;1s&quot;<br>       }()<br>       time.Sleep(20 * time.Second) // the goroutine above will run before this Sleep returns<br>       t.Log(time.Since(start))     // always logs &quot;2s&quot;<br>    })<br>}</pre><p>Lets condsider the following example that uses Wait, ony of key functions of synctest package that.</p><pre>func TestContextAfterFunc(t *testing.T) {<br>    synctest.Test(t, func(t *testing.T) {<br>       ctx, cancel := context.WithCancel(t.Context())<br><br>       afterFuncCalled := false<br>       context.AfterFunc(ctx, func() {<br>          afterFuncCalled = true<br>       })<br><br>       synctest.Wait()<br>       if afterFuncCalled {<br>          t.Fatalf(&quot;before context is canceled: AfterFunc called&quot;)<br>       }<br><br>       cancel()<br>       synctest.Wait()<br>       if !afterFuncCalled {<br>          t.Fatalf(&quot;before context is canceled: AfterFunc not called&quot;)<br>       }<br>    })<br>}</pre><p>The synctest.Wait function call acts as a synchronization point between goroutines within a <strong>bubble</strong>.<br> Wait returns only when the bubble becomes <em>durably blocked</em> — that is, when <strong>all goroutines inside it</strong> are durably blocked. This moment is crucial — similar to the <em>collision event</em> in the discrete-event simulation (DES) we discussed earlier.. When this happened we need either to supply goroutines with something that will let them proceed or analyze test results and finalize it. Only an event <em>inside the bubble</em> can unblock a durably blocked goroutine. If no such event occurs, both the goroutine and the bubble remain durably blocked(deadlock). Only specific operations might durably block gorutuines:</p><pre>1) a send or receive on a nil channel<br>2) a send or receive blocked on a channel created within the same bubble<br>3) a select statement where every case is durably blocking<br>4) time.Sleep<br>5) sync.Cond.Wait<br>6) sync.WaitGroup.Wait</pre><p><strong>Important:</strong> Operations on a sync.Mutex are <strong>not durably blocking</strong>.<br> Similarly, external operations such as file or network I/O are also <strong>not durably blocking</strong>, and therefore will not unblock a goroutine waiting on Wait(). This means your code will remain stuck until the external event actually occurs. To avoid this, it’s recommended to use the net.Pipe function, which creates a pair of net.Conn objects connected through an in-memory network connection. These can safely be used in synctest tests. Example of using in-memory network connection under the hood of http.Transport.</p><pre>func TestHTTPTransport100Continue(t *testing.T) {<br>    synctest.Test(t, func(*testing.T) {<br>       // Create an in-process fake network connection.<br>       // We cannot use a loopback network connection for this test,<br>       // because goroutines blocked on network I/O prevent a synctest<br>       // bubble from becoming idle.<br>       srvConn, cliConn := net.Pipe()<br>       defer cliConn.Close()<br>       defer srvConn.Close()<br><br>       tr := &amp;http.Transport{<br>          // Use the fake network connection created above.<br>          DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {<br>             return cliConn, nil<br>          },<br>          // Enable &quot;Expect: 100-continue&quot; handling.<br>          ExpectContinueTimeout: 5 * time.Second,<br>       }<br><br>       // Send a request with the &quot;Expect: 100-continue&quot; header set.<br>       // Send it in a new goroutine, since it won&#39;t complete until the end of the test.<br>       body := &quot;request body&quot;<br>       go func() {<br>          req, _ := http.NewRequest(&quot;PUT&quot;, &quot;http://test.tld/&quot;, strings.NewReader(body))<br>          req.Header.Set(&quot;Expect&quot;, &quot;100-continue&quot;)<br>          resp, err := tr.RoundTrip(req)<br>          if err != nil {<br>             t.Errorf(&quot;RoundTrip: unexpected error %v\n&quot;, err)<br>          } else {<br>             resp.Body.Close()<br>          }<br>       }()<br><br>       // Read the request headers sent by the client.<br>       req, err := http.ReadRequest(bufio.NewReader(srvConn))<br>       if err != nil {<br>          t.Fatalf(&quot;ReadRequest: %v\n&quot;, err)<br>       }<br><br>       // Start a new goroutine copying the body sent by the client into a buffer.<br>       // Wait for all goroutines in the bubble to block and verify that we haven&#39;t<br>       // read anything from the client yet.<br>       var gotBody bytes.Buffer<br>       go io.Copy(&amp;gotBody, req.Body)<br>       synctest.Wait()<br>       if got, want := gotBody.String(), &quot;&quot;; got != want {<br>          t.Fatalf(&quot;before sending 100 Continue, read body: %q, want %q\n&quot;, got, want)<br>       }<br><br>       // Write a &quot;100 Continue&quot; response to the client and verify that<br>       // it sends the request body.<br>       srvConn.Write([]byte(&quot;HTTP/1.1 100 Continue\r\n\r\n&quot;))<br>       synctest.Wait()<br>       if got, want := gotBody.String(), body; got != want {<br>          t.Fatalf(&quot;after sending 100 Continue, read body: %q, want %q\n&quot;, got, want)<br>       }<br><br>       // Finish up by sending the &quot;200 OK&quot; response to conclude the request.<br>       srvConn.Write([]byte(&quot;HTTP/1.1 200 OK\r\n\r\n&quot;))<br><br>       // We started several goroutines during the test.<br>       // The synctest.Test call will wait for all of them to exit before returning.<br>    })<br>}</pre><p><strong>Conclusion:</strong><br> The testing/synctest package is a powerful tool that makes concurrent tests run <strong>deterministically</strong> and <strong>significantly faster</strong> compared to regular execution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=463a07eda814" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn How to Use TLS Bootstrapping in Kubernetes]]></title>
            <link>https://medium.com/kubernetes-tutorials/learn-how-to-use-tls-bootstrapping-in-kubernetes-9c54787663a5?source=rss-60f06e874747------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c54787663a5</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubelet]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Gleb Stepanov]]></dc:creator>
            <pubDate>Fri, 21 Jun 2019 12:35:29 GMT</pubDate>
            <atom:updated>2019-06-24T10:22:22.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*M5msENOb758E9Ty2hanBow.png" /></figure><p>Setting up a master and worker node for TLS bootstrapping can be tricky because many configuration steps are involved, so we decided to walk you through the process of enabling this useful feature in Kubernetes. Let’s get started!</p><h3>What Is TLS Bootstrapping?</h3><p>Kubernetes recommends making communication between node components such as kubelet and kube-proxy and master components private and secure. To achieve this, we need to distribute TLS certificates for node components and sign them with the master CA. Prior to Kubernetes v1.4, users had to do most of the TLS bootstrapping work such as issuing and distributing certificates manually. In particular, <a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet-tls-bootstrapping/#kube-apiserver-configuration">the following steps were involved</a>:</p><ol><li>Creating a Certificate Authority (CA) key and a certificate</li><li>Distributing the CA certificate to the master(s)</li><li>Creating a certificate and a key for each kubelet.</li><li>Signing the kubelet certificate using the CA key on the master</li><li>Distributing the kubelet key and the signed certificate to the node where the kubelet will be running</li></ol><p>A certificate request and signing API was introduced in Kubernetes v1.4 to simplify this process. More specifically, it automates steps 3 forward. Thus, TLS bootstrapping may be described as a mechanism for the automatic retrieval of certificates from the API to allow newly created nodes(s) to communicate with master(s) securely. This feature became Generally Available in Kubernetes v. 1.12.</p><h3>Tutorial</h3><p>For the purpose of this article, we will use kubeadm to provision a master node, create a worker node, set up it manually, and connect to the master. Instructions on creating a single-master K8s cluster can be found <a href="https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/">here</a>.</p><p>Assuming that a node has been created, we need the following information:</p><ol><li>master host:port</li><li>a bootstrap token</li><li>a CA certificate</li></ol><p>First two can be obtained from the kubeadm init output down below:</p><pre>Your Kubernetes control-plane has initialized successfully!</pre><pre>To start using your cluster, you need to run the following as a regular user:</pre><pre>mkdir -p $HOME/.kube</pre><pre>sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config</pre><pre>sudo chown $(id -u):$(id -g) $HOME/.kube/config</pre><pre>You should now deploy a Pod network to the cluster.</pre><pre>Run &quot;kubectl apply -f [podnetwork].yaml&quot; with one of the options listed at:</pre><pre>https://kubernetes.io/docs/concepts/cluster-administration/addons/</pre><pre>Then you can join any number of worker nodes by running the following on each as root:</pre><pre>kubeadm join &lt;master-ip&gt;:&lt;master-port&gt; --token &lt;bootstrap-token&gt; --discovery-token-ca-cert-hash sha256:&lt;ca-cert-hash&gt;</pre><p>A CA cert can be found on a master node in /etc/kubernetes/pki/ca.crt , which is its default location.</p><p>To bootstrap a new node, we need only two binaries: kubectl and kubelet .<br>Download those binaries from <a href="https://kubernetes.io/docs/setup/release/notes/#server-binaries">here</a> and unpack them:</p><pre>wget https://dl.k8s.io/v1.13.4/kubernetes-server-linux-amd64.tar.gz tar -xvf kubernetes-server-linux-amd64.tar.gz <br>sudo cp kubernetes/server/bin/kubelet /usr/bin <br>sudo cp kubernetes/server/bin/kubectl /usr/bin</pre><p>A container runtime is also a required node component, so don’t forget to install Docker or any other container runtime you prefer (e.g., rkt):</p><pre>sudo apt-get update sudo apt install -y docker.io</pre><p>Next, create a folder for storing Kubernetes-related files:</p><pre>sudo mkdir /etc/kubernetes<br>sudo mkdir /etc/kubernetes/manifests<br>sudo mkdir /etc/kubernetes/pki</pre><p>Copy the ca.crt from the master to /etc/kubernetes/pki</p><p>Now, we are almost prepared for the TLS bootstrapping of a new node. We do need two additional things, though:</p><ol><li>A path to kubeconfig that does not exist yet and will be stored there<br>after successful bootstrap:--kubeconfig</li><li>A path to bootstrap config: --bootstrap-kubeconfig</li></ol><p>We can either create a bootstrap config manually using kubectl config command or just copy the kubeconfig from a master node:</p><pre>sudo kubectl config --kubeconfig=/etc/kubernetes/bootstrap-kubeconfig set-cluster kubernetes --server=&#39;https://&lt;master-host&gt;:&lt;master-port&gt;&#39; --certificate-authority=/etc/kubernetes/pki/ca.crt --embed-certs=true </pre><pre>sudo kubectl config --kubeconfig=/etc/kubernetes/bootstrap-kubeconfig set-credentials tls-bootstrap-token-user --token=&lt;bootstrap-token&gt; </pre><pre>sudo kubectl config --kubeconfig=/etc/kubernetes/bootstrap-kubeconfig set-context tls-bootstrap-token-user@kubernetes --user=tls-bootstrap-token-user --cluster=kubernetes </pre><pre>sudo kubectl config --kubeconfig=/etc/kubernetes/bootstrap-kubeconfig use-context tls-bootstrap-token-user@kubernetes</pre><p>The last step we need to do is to create a systemd<br>file in /etc/systemd/system/kubelet.service to run kubelet as a daemon.</p><p>We use the RotateKubeletClientCertificate feature gate that enables certificate rotation. This Beta feature enables kubelet to update a certificate each time it’s going to expire.</p><pre>[Service] <br>Restart=always <br>ExecStart=/usr/bin/kubelet --kubeconfig=/etc/kubernetes/kubeconfig \\ <br>--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubeconfig \\ <br>--pod-manifest-path=/etc/kubernetes/manifests \\ <br>--feature-gates=RotateKubeletClientCertificate=true \\ <br>--rotate-certificates <br>[Install] <br>WantedBy=multi-user.target</pre><p>Reload systemd daemon and enable kubelet service to run on startup.</p><pre>systemctl daemon-reload<br>systemctl enable kubelet<br>systemctl start kubelet</pre><p>Finally, check that node is up and running in Ready state:</p><pre>kubectl get  no</pre><pre>NAME         STATUS   ROLES    AGE   VERSION</pre><pre>instance-1   Ready    master   15m   v1.13.4</pre><pre>instance-2   Ready    &lt;none&gt;   30s   v1.13.4</pre><h3>Conclusion</h3><p>That’s it! We have successfully enabled TLS bootstrapping of a new node. This automatic feature makes connecting nodes to the cluster and securing their communication with the kube-apiserver much easier. In particular, we do not need to manually create kubelet certificates and sign them with the master certificates because this process is automatically handled by the Kubernetes TLS API.</p><p>Below is the list of references that will help you install a single-master K8s cluster with kubeadm and learn more about TLS bootstrapping:</p><ul><li><a href="https://kubernetes.io/docs/setup/independent/install-kubeadm/">https://kubernetes.io/docs/setup/independent/install-kubeadm/</a></li><li><a href="https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/">https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/</a></li><li><a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet-tls-bootstrapping/">https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet-tls-bootstrapping/</a></li><li><a href="https://kubernetes.io/docs/tasks/tls/certificate-rotation/">https://kubernetes.io/docs/tasks/tls/certificate-rotation/</a></li><li><a href="https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/">https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/</a></li><li><a href="https://kubernetes.io/docs/reference/access-authn-authz/bootstrap-tokens/">https://kubernetes.io/docs/reference/access-authn-authz/bootstrap-tokens/</a></li><li><a href="https://medium.com/@toddrosner/kubernetes-tls-bootstrapping-cf203776abc7">https://medium.com/@toddrosner/kubernetes-tls-bootstrapping-cf203776abc7</a></li></ul><p><em>Originally published at </em><a href="https://supergiant.io/blog/tls-bootstrapping-in-kubernetes/"><em>https://supergiant.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c54787663a5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kubernetes-tutorials/learn-how-to-use-tls-bootstrapping-in-kubernetes-9c54787663a5">Learn How to Use TLS Bootstrapping in Kubernetes</a> was originally published in <a href="https://medium.com/kubernetes-tutorials">Supergiant.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>