Random Ramblings My two cents http://localhost:4000/ Wed, 06 May 2020 17:52:25 +1000 Wed, 06 May 2020 17:52:25 +1000 Jekyll v4.0.0 Run Kubernetes clusters across AWS and vSphere with TKG <p>It is common for many large organizations to run their Kubernetes workloads on more than one cloud provider. It is a great strategy to utilise the benefits of on-prem and public cloud. In this blog, I will show you how to create, run and manage clusters across AWS and vSphere using Tanzu Kubernetes Grid (TKG).</p> <h2 id="brief-intro-to-tkg">Brief intro to TKG</h2> <p>TKG is a bundle of tools that help run k8s in a production environment. In addition to vanilla kubernetes, TKG includes Open Source tools like Cluster API, Calico for networking, Fluent Bit for logging, Contour for ingress etc.</p> <h2 id="prerequisites">Prerequisites</h2> <ol> <li>Deploy TKG management cluster to Amazon EC2 - Follow steps in <a href="https://docs.vmware.com/en/VMware-Tanzu-Kubernetes-Grid/1.0/vmware-tanzu-kubernetes-grid-10/GUID-install-tkg-aws.html">docs</a></li> <li>Deploy TKG on vSphere - Follow steps in <a href="https://docs.vmware.com/en/VMware-Tanzu-Kubernetes-Grid/1.0/vmware-tanzu-kubernetes-grid-10/GUID-install-tkg-vsphere.html">docs</a> Alternatively, if you are on <em>vSphere 7</em>, you could enable kubernetes Workload management and skip step and follow <a href="https://docs.vmware.com/en/VMware-Tanzu-Kubernetes-Grid/1.0/vmware-tanzu-kubernetes-grid-10/GUID-tanzu-k8s-clusters-connect-vsphere7.html">this link</a> to add vSphere management cluster to your TKG cli.</li> </ol> <h2 id="multiple-tkg-management-clusters">Multiple TKG management clusters</h2> <p>Now that we have set up two different TKG clusters, lets see how we can manage them using the TKG cli.</p> <p><code class="highlighter-rouge">tkg get management-cluster</code></p> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>+-------------------------------+---------------------------------------------------------------+ | MANAGEMENT CLUSTER NAME | CONTEXT NAME | +-------------------------------+---------------------------------------------------------------+ | tkg-mgmt-aws-zzzzz* | tkg-mgmt-aws-zzzzz-admin@tkg-mgmt-aws-zzzzz | | wcp.vsphere.test.io | wcp.vsphere.test.io | +-------------------------------+---------------------------------------------------------------+ </code></pre></div></div> <ul> <li>indicates the management cluster which is selected. AWS management cluster is selected at the moment.</li> </ul> <p>Create a cluster on AWS:</p> <p><code class="highlighter-rouge">tkg create cluster my-aws-cluster --plan=dev --kubernetes-version=v1.17.3+vmware.2</code></p> <p>Once it is done, run the following command to make sure the cluster is created. <code class="highlighter-rouge">tkg get cluster</code></p> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>+----------+-------------+ | NAME | STATUS | +----------+-------------+ | my-aws-cluster | Provisioned | +----------+-------------+ </code></pre></div></div> <h3 id="create-a-cluster-on-vsphere">Create a cluster on vSphere:</h3> <p>Select the vSphere k8s cluster</p> <p><code class="highlighter-rouge">tkg set management-cluster wcp.abc.test.io</code></p> <p>To create a cluster in vSphere,</p> <p><code class="highlighter-rouge">tkg create cluster my-tkg-cluster --plan=dev --namespace=demo --kubernetes-version=v1.16.8+vmware.1-tkg.3.60d2ffd</code></p> <p>Once the cluster is created, you could verify by running the command or you could login to the vCenter UI to take a look. <img src="/assets/img/vsphere-cluster.png" alt="Cluster in vCenter" /></p> <h2 id="key-takeaways">Key takeaways:</h2> <ol> <li>I could use different versions of kubernetes across AWS and vSphere.</li> <li>I could use different storage classes across AWS and vSphere. Edit ~/.tkg/config.yaml to change storage classes or vm classes.</li> <li>Consistent experience creating clusters across the two IaaS. I can use the same TKG Cli to manage clusters. Yay!</li> </ol> Large organizations to run their Kubernetes workloads on more than one cloud provider. Here is how TKG helps manage k8s clusters on multiple IaaS Wed, 06 May 2020 00:00:00 +1000 http://localhost:4000/blog/tkg-on-aws-vsphere/ http://localhost:4000/blog/tkg-on-aws-vsphere/ tkg tanzu kubernetes vsphere vmware containers aws multicloud Kubernetes vs Containers <!-- wp:paragraph --> <p>If you interact with Software development teams as a part of your role, you would have heard the term Kubernetes (or 'K8s' as it is fondly known). This is a complicated concept to understand, especially if you do not have a Software Engineering background. </p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>Last week, I was in a meeting with a few non-technical colleagues who were sharing customer stories around containers and Kubernetes. They were using jargon like containers, docker, kubernetes in this conversation.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>A curious colleague who was listening in turned to me and asked “What is the difference between a Container and Kubernetes?” There was silence in the room, everyone eagerly waiting to hear this technical person’s answer.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>The easy answer  —  Docker is used to create <em>containers</em> and Kubernetes is used to <em>orchestrate</em> them. I could get away with this explanation, but that is just throwing more tech jargon to the fire. How can you clearly articulate&nbsp; the differences between these technologies, let alone explain these concepts in a human-friendly, digestible way?</p> <!-- /wp:paragraph --> <!-- wp:heading {"level":3} --> <h3><strong>B</strong>ackground</h3> <!-- /wp:heading --> <!-- wp:paragraph --> <p>Let’s say, we are building a simple website called <em>chatter.com </em>where people can post short updates about their life<em>.</em></p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>Here the engineers build this application in a programming language like java. They get it working on their machine, but you cannot see what they have built until this software application is available on the internet. Hence, this software needs to be <strong>deployed </strong>somewhere.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>This application can be deployed on the company’s cloud infrastructure — it’s just computers on someone else’s hardware.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>Since the application is written in java, the computer needs java to run the website. The engineers therefore package this application with java, so that it can be run on any computer just like it runs on the engineer’s machine.&nbsp;</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>This package is called a <strong>container</strong>. Just like regular airtight food containers, containers in the digital world come in different shapes and sizes. Based on the size of containers, more than one container can run on a computer.&nbsp;</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p><em>We have our chatter.com running with containers. So what’s the deal with Kubernetes?</em></p> <!-- /wp:paragraph --> <!-- wp:heading {"level":3} --> <h3><strong>C</strong>ontainers to<strong> K</strong>ubernetes</h3> <!-- /wp:heading --> <!-- wp:paragraph --> <p>For the next part, let’s pretend that the Cloud Infrastructure is like a 2x2 storage unit, where each shelf is a computer. Containers are just boxes. There are already a few (black coloured) containers on these shelves.</p> <!-- /wp:paragraph --> <!-- wp:image {"width":780,"height":611} --> <figure class="wp-block-image is-resized"><img src="https://lh3.googleusercontent.com/iVBfTvABS0IlmOE8FZnCvK_-ahp1-mzEFRdC7tjQtBQfb2hGcnhLHbo3002H7m5TgzhDvlL3fMjXbfcqtl1j9_oM0L-1_aM3KkyIrpe-uIvCMNmgAZ3T4RAzetGbCb3KLenwsGw1" alt="" width="780" height="611" /><figcaption>Each cube is a computer. Pink box is the chatter container</figcaption></figure> <!-- /wp:image --> <!-- wp:paragraph --> <p>Engineers write scripts to drop the <em>chatter</em> container on an available shelf in the storage unit. This container is running on the top-right shelf (the pink container in the image).</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>Now, imagine there is an earthquake and this container suddenly crashes to the floor. Yep, sometimes websites crash too! Someone has to repeat the previous step again to replace the container.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>How great would it be if there was someone watching over all these containers, making sure they are always running well? Enter <strong>Kubernetes</strong> to the rescue.</p> <!-- /wp:paragraph --> <!-- wp:image {"id":38,"sizeSlug":"large"} --> <figure class="wp-block-image size-large"><img src="https://solutionarchitecturedotblog.files.wordpress.com/2020/04/image2_k8s.png?w=1024" alt="Kubernetes healing a burning pod " class="wp-image-38" /><figcaption>Kubernetes healing a burning pod<br /></figcaption></figure> <!-- /wp:image --> <!-- wp:paragraph --> <p>When a container crashes, k8s tries to heal the container and brings it back to life. It makes sure all containers are healthy and safe. K8s helps with finding a vacant spot for containers and allocates them to the appropriate shelf based on its size; ensuring the optimal use of shelf space.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>This is a very high level differentiation between containers and k8s. There is more to k8s than allocating compute to containers. If you are interested in learning more, please leave a comment. I will share more details in subsequent posts. :) </p> <!-- /wp:paragraph --> Large organizations to run their Kubernetes workloads on more than one cloud provider. Here is how TKG helps manage k8s clusters on multiple IaaS Sat, 14 Mar 2020 00:00:00 +1100 http://localhost:4000/blog/kubernetes-vs-containers/ http://localhost:4000/blog/kubernetes-vs-containers/ kubernetes containers docker cloud How to test state in React components? <h4 id="do-not-test-the-state">Do not test the state!</h4> <p>Although it is tempting to use <code class="highlighter-rouge">state()</code> from enzyme to test the value of your component state from jest tests, it is a code smell to do so. Because, <code class="highlighter-rouge">state</code> is internal to the component. Testing the new value of state from your unit test is like testing private methods (in java/ruby..).</p> <h3 id="how-else-do-i-test-state-change">How else do I test state change?</h3> <p>Now that is a different question.</p> <p>When writing unit tests in jest/jasmine, it is a good practice to describe the behavior of your component. Tests are documentation after all. <code class="highlighter-rouge">state</code> is an internal detail of how you have implemented the functionality.</p> <h2 id="example">Example:</h2> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>class Counter extends Component { constructor(props) { super(props); this.state= { count: 1 }; } increment = () =&gt; { this.setState((prevState) =&gt; ({count: prevState.count + 1})); } render() { return ( &lt;div&gt; &lt;h2&gt;Number of votes: {this.state.count}&lt;/h2&gt; &lt;p&gt; This is my code. Please upvote!&lt;/p&gt; &lt;button onClick={this.increment}&gt;Upvote!&lt;/button&gt; &lt;/div&gt; ); } } </code></pre></div></div> <p>In the example above, clicking on the button increments the number of votes on screen.</p> <p>To test this in jest,</p> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>it('updates number of votes', () =&gt; { const wrapper = shallow(&lt;Counter/&gt;); wrapper.find('button').simulate('click'); wrapper.update(); // Read: enzyme update expect(wrapper.find('h2').text()).toEqual('Number of votes: 2'); }); </code></pre></div></div> <p><em>To conclude, use your tests to verify the behavior and not the implementation.</em></p> <p>What is your take on testing state changes? Let me know in the comments below! Happy coding :)</p> Do not test the state. Testing the new value of state from your unit test is like testing private methods Mon, 09 Jul 2018 00:00:00 +1000 http://localhost:4000/blog/how-to-test-react-state/ http://localhost:4000/blog/how-to-test-react-state/ react state redux jest enzyme test state in react how to test react state in component Circuit Breaker Pattern <p>With Micro-services pattern, we rely more on the availability of services to connect with. Even if the services being consumed are written in a way to handle errors gracefully, there is a few more factors, like Network Connections, which could break your application. This makes it important to anticipate and handle failures when interacting with external systems.</p> <p>The idea is similar to the Circuit Breaker in electrical systems. When you try to consume more electricity than the treshold, the fuse would blow up, leaving the electric circuit open. This prevents you from overloading the electrical circuit again. You need to close the circuit (with a copper wire) before you can consume electricity.</p> <p>Circuit Breaker pattern is similar. If a remote system is unhealthy, the circuit is left open, so that your application does not wait for a timeout from the remote system repeatedly.</p> <p>The difference with Circuit breaker in Software is that, there is no need for a human intervention in fixing the circuit. After a certain amount of time, the circuit breaker goes to a <code class="highlighter-rouge">half-open</code> state, in which the next call to the remote system is made to the remote system. If this call passes, the circuit gets <code class="highlighter-rouge">closed</code>. Else, it remains <code class="highlighter-rouge">open</code>.</p> <h2 id="dont-do-it-if-it-hurts">Don’t do it if it hurts!</h2> <p><em>This post is based on the book <strong>Release It!</strong> by <strong>Michael T.Nygard</strong>.</em></p> <p>With Micro-services pattern, we rely more on the availability of services to connect with. Even if the services being consumed are written in a way to handle errors gracefully, there is a few more factors, like Network Connections, which could break your application. This makes it important to anticipate and handle failures when interacting with external systems.</p> Sun, 23 Jul 2017 00:00:00 +1000 http://localhost:4000/blog/circuit-breaker-pattern/ http://localhost:4000/blog/circuit-breaker-pattern/ Tech Patterns Spring Boot The time I started running <p>I remember running my first 8 km and not being able to walk the whole day after. I thought I was just not fit. I tried multiple times, with short distance and long distance running. But my feet hurt so bad that I gave up on running.</p> <p>A lot of articles suggested that I need better shoes. I bought a pair from Decathlon (40 AUD). It was so comfortable for my zumba classes. I decided to give running another chance. But, Zumba shoes are not running shoes.&nbsp;</p> <p>I tried couple more shoes from big brands like Nike &amp; Reebok. They were amazing for weight training. But&nbsp;horrendous for running.</p> <p>At this point, I thought it was just me. <em><b>My feet are not designed for running.</b></em>😒</p> <p>Few months later, I fell in love with a Nike running shoe, the moment I tried it on. They were so weightless and the soles were thick and comfortable.</p> <p>The same day I went for a run. <br /><em>I felt like a child who just started running. </em><br />My feet did not hurt!! <br />It made a huge difference in the way I looked at running. <br />It motivated me to keep running.</p> <p>Choosing the right shoes make a huge difference. Those pair of shoes I am comfortable in, may not be the right fit&nbsp;for you. <strong>Running shoes are an investment</strong>.</p> <p>It takes time to find your flavor. Don't settle for less comfortable, cheap shoes.</p> <p>Keep searching for those perfect shoes.👟</p> <p>I remember running my first 8 km and not being able to walk the whole day after. I thought I was just not fit. I tried multiple times, with short distance and long distance running. But my feet hurt so bad that I gave up on running.</p> <p>A lot of articles suggested that I need better shoes. I bought a pair from Decathlon (40 AUD). It was so comfortable for my zumba classes. I decided to give running another chance. But, Zumba shoes are not running shoes.&nbsp;</p> <p>I tried couple more shoes from big brands like Nike &amp; Reebok. They were amazing for weight training. But&nbsp;horrendous for running.</p> <p>At this point, I thought it was just me. <em><b>My feet are not designed for running.</b></em>😒</p> <p>Few months later, I fell in love with a Nike running shoe, the moment I tried it on. They were so weightless and the soles were thick and comfortable.</p> <p>The same day I went for a run. <br /><em>I felt like a child who just started running. </em><br />My feet did not hurt!! <br />It made a huge difference in the way I looked at running. <br />It motivated me to keep running.</p> <p>Choosing the right shoes make a huge difference. Those pair of shoes I am comfortable in, may not be the right fit&nbsp;for you. <strong>Running shoes are an investment</strong>.</p> <p>It takes time to find your flavor. Don't settle for less comfortable, cheap shoes.</p> <p>Keep searching for those perfect shoes.👟</p> Sat, 03 Jun 2017 00:00:00 +1000 http://localhost:4000/blog/why-i-hated-running/ http://localhost:4000/blog/why-i-hated-running/ Life Running Fitness Training that voice in my head <pre>Ouch. Did I hear my ankle crack?<br />OMG. It could be a sprain.<br />I could have torn some ligaments.<br />Let me stop here.<br />Water. I need water!<br /><br />Argh. Not even half way there?<br />Why not just turn around?<br />Why do I breathe so fast?<br />Is it normal to breathe through my mouth?<br /><br />Phew. Made it half way.<br />Do I have to go back right now?<br />I can't feel my legs!!<br />I am going to fall on my face.<br />Oooh. Gelato house.<br /><br /><em>We are almost done.</em><br /><em>Actually, my legs don't hurt so bad.</em><br /><em>I feel alive; very much alive.</em><br /><br /><strong><em>Why was I so negative about running anyway?</em></strong></pre> <pre>Ouch. Did I hear my ankle crack?<br />OMG. It could be a sprain.<br />I could have torn some ligaments.<br />Let me stop here.<br />Water. I need water!<br /><br />Argh. Not even half way there?<br />Why not just turn around?<br />Why do I breathe so fast?<br />Is it normal to breathe through my mouth?<br /><br />Phew. Made it half way.<br />Do I have to go back right now?<br />I can't feel my legs!!<br />I am going to fall on my face.<br />Oooh. Gelato house.<br /><br /><em>We are almost done.</em><br /><em>Actually, my legs don't hurt so bad.</em><br /><em>I feel alive; very much alive.</em><br /><br /><strong><em>Why was I so negative about running anyway?</em></strong></pre> Fri, 02 Jun 2017 00:00:00 +1000 http://localhost:4000/blog/training-that-voice/ http://localhost:4000/blog/training-that-voice/ Life Running Fitness Break Stereotypes <p><i> “Boys will be boys<br /> Play with the girls” </i></p> <p>says mom to 5 year old Sarah when she complains about being teased by the boys, for missing a wicket at the cricket game.</p> <p>This creates a fear in her heart.</p> <p>A fear which makes her find boys intimidating. A fear which stops her from getting better at a game she really wants to play.</p> <p>10 years later, this fear stops her from taking a class she wants to take, Because the same “boys” are in it. She is not matured enough to take the road less taken; She wants to be at a place which she considers her safe zone.</p> <p>15 years later, this fear stops her from learning to code, Because she has not seen many women who are good at it.</p> <p>Stereotypes are created by us. They affect our decisions. They affect our way of life.</p> <p><i> “Boys will be boys<br /> Play with the girls” </i></p> Sat, 11 Mar 2017 00:00:00 +1100 http://localhost:4000/blog/gender-stereotypes/ http://localhost:4000/blog/gender-stereotypes/ Life IWD Break Stereotypes <p>Dear women,</p> <p> Don't get carried away by the stereotypes set by media;<br /> Nobody but you can define what you are capable of. </p> <p>Don’t be intimidated by the men in the floor;<br /> Your skills are equally important as theirs.</p> <p>Don’t be afraid of being wrong;<br /> Everyone makes mistakes and so will you.</p> <p>You are strong. You are beautiful;<br /> Feel free to express yourself.<br /></p> <p>Let not the stereotypes stop you from expressing yourself.<br /></p> <p><i> This International Women’s day, I pledge to be bold for change and challenge stereotypes. </i></p> <p><a href="https://www.internationalwomensday.com/BeBold">#BeBoldForChange</a></p> <p>Dear women,</p> <p> Don't get carried away by the stereotypes set by media;<br /> Nobody but you can define what you are capable of. </p> <p>Don’t be intimidated by the men in the floor;<br /> Your skills are equally important as theirs.</p> Tue, 07 Mar 2017 00:00:00 +1100 http://localhost:4000/blog/break-stereotypes/ http://localhost:4000/blog/break-stereotypes/ Life IWD Connect with MergeProps <p><code class="highlighter-rouge">MergeProps</code> is the third argument to the <a href="https://github.com/reactjs/react-redux/blob/master/docs/api.md">connect</a> function. It is a function which is used to select a slice of the props from state and dispatch.</p> <p><code class="highlighter-rouge">SaveAllContainer</code> maps the todo items from store to props and a <code class="highlighter-rouge">save</code> prop which dispatches an action to save all items.</p> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>const mapStateToProps = (state) =&gt; { return { items: state.items }; }; const mapDispatchToProps = (dispatch) =&gt; { return { save: (items) =&gt; dispatch({type: "SAVE_ALL", items}) }; }; const SaveAllContainer = connect(mapStateToProps, mapDispatchToProps)(SaveAll); </code></pre></div></div> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>const SaveAll = ({save, items}) =&gt; { return &lt;button onClick={() =&gt; save(items)}&gt;Save All &lt;/button&gt;; }; </code></pre></div></div> <p><code class="highlighter-rouge">items</code> is being passed to the component and back to the container. But, the presentational component does not need to know about the <code class="highlighter-rouge">items</code>.</p> <p>I would like it, if the <code class="highlighter-rouge">save</code> function in props knows about the <code class="highlighter-rouge">items</code> to be saved, so that the items need not be passed in props. Ideally, the container should return something like this:</p> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{ save: () =&gt; dispatch({type: "SAVE_ALL", items: state.items}) } </code></pre></div></div> <p>The best place to combine <code class="highlighter-rouge">state</code> and <code class="highlighter-rouge">dispatch</code> is <code class="highlighter-rouge">mergeProps</code>.</p> <div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>const mapDispatchToProps = (dispatch) =&gt; { return { dispatchSave: (items) =&gt; dispatch({type: "SAVE_ALL", items}) }; } const mergeProps = (propsFromState, propsFromDispatch, ownProps) { return { save: propsFromDispatch.dispatchSave(propsFromState.items) }; }; const SaveAllContainer = connect(mapStateToProps, mapDispatchToProps, mergeProps)(SaveAll); </code></pre></div></div> <p>The <code class="highlighter-rouge">SaveAll</code> component is not aware of the <code class="highlighter-rouge">items</code> anymore. <code class="highlighter-rouge">mergeProps</code> is now responsible for passing the items to be saved.</p> <p>When the third argument is not passed to <code class="highlighter-rouge">connect</code>, the default implementation of <code class="highlighter-rouge">mergeProps</code> combines the <code class="highlighter-rouge">ownProps</code>, <code class="highlighter-rouge">mapStateToProps</code> and <code class="highlighter-rouge">mapDispatchToProps</code>.</p> <p><code class="highlighter-rouge">mergeProps</code> is where you can filter the props being passed to the component. Especially in situations like above, where you intend to use properties from store as parameters to dispatch actions, <code class="highlighter-rouge">mergeProps</code> is the cleanest choice.</p> <p><code class="highlighter-rouge">MergeProps</code> is the third argument to the <a href="https://github.com/reactjs/react-redux/blob/master/docs/api.md">connect</a> function. It is a function which is used to select a slice of the props from state and dispatch.</p> Thu, 02 Mar 2017 00:00:00 +1100 http://localhost:4000/blog/connect-with-mergeprops/ http://localhost:4000/blog/connect-with-mergeprops/ Tech React Redux Javascript