<?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 Rebeccah Wambui on Medium]]></title>
        <description><![CDATA[Stories by Rebeccah Wambui on Medium]]></description>
        <link>https://medium.com/@wambuirebeka?source=rss-5bd656a64e93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*csMETkuqoKBy-jHOF0y50g.jpeg</url>
            <title>Stories by Rebeccah Wambui on Medium</title>
            <link>https://medium.com/@wambuirebeka?source=rss-5bd656a64e93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:40:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wambuirebeka/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[Advanced GoLang Concepts: Channels, Context, and Interfaces. Part 2]]></title>
            <link>https://medium.com/@wambuirebeka/advanced-golang-concepts-channels-context-and-interfaces-part-2-e24397f7edf9?source=rss-5bd656a64e93------2</link>
            <guid isPermaLink="false">https://medium.com/p/e24397f7edf9</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[technical-writing]]></category>
            <dc:creator><![CDATA[Rebeccah Wambui]]></dc:creator>
            <pubDate>Tue, 03 Oct 2023 14:19:47 GMT</pubDate>
            <atom:updated>2023-10-09T06:47:15.581Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sicq2ozcdL-ZEYxn" /><figcaption>Photo by <a href="https://unsplash.com/@mustafa_omar?utm_source=medium&amp;utm_medium=referral">Mustafa Omar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>If you are reading this, then you’ve probably read part one, on Golang Channels, how channels are used to achieve concurrency in Go, different ways to implement channels as well as some real-life examples. If not, you can find the first part of this short series <a href="https://medium.com/@wambuirebeka/advanced-golang-concepts-channels-context-and-interfaces-dc3b71cd0ed8">here</a>.</p><p><a href="https://medium.com/@wambuirebeka/advanced-golang-concepts-channels-context-and-interfaces-dc3b71cd0ed8">Advanced GoLang Concepts: Channels, Context, and Interfaces.</a></p><p>This article is a continuation of the Advanced GoLang concepts, and we’ll be covering contexts and Interfaces. As usual, It will be pretty cool if you open your IDE, and follow the steps, as we learn together!</p><h3>Context</h3><p>A <a href="https://pkg.go.dev/context">context</a> defines the Context type, which carries deadlines, cancellation signals, and other request-scoped values across API boundaries and between processes.</p><p>Let’s look at an example, say we have this simple program that gets users from an API and returns the size of the data fetched.</p><pre>func main() {<br><br> // create http request<br> req, err := http.NewRequest(http.MethodGet, &quot;https://jsonplaceholder.typicode.com/users&quot;, nil)<br> if err != nil {<br>  fmt.Printf(&quot;error fetching users&quot;)<br> }<br><br> //perform the http request<br> res, err := http.DefaultClient.Do(req)<br> if err != nil {<br>  fmt.Printf(&quot;error processing request&quot;)<br> }<br><br> defer res.Body.Close()<br><br> //get body from the response<br> data, err := io.ReadAll(res.Body)<br> if err != nil {<br>  fmt.Printf(&quot;error reading response body&quot;)<br> }<br><br> fmt.Printf(&quot;data of size %d\n&quot;, len(data))<br>}</pre><p>Response:</p><pre>% go run .<br>data of size 5645</pre><p>Assuming we want to cancel the request if it takes longer than a certain amount of time, we’ll use<strong><em> context</em></strong> to cancel this request.</p><pre>timeoutContext, cancel := context.WithTimeout(context.Background(), time.Millisecond * 100)<br> defer cancel()<br><br>req, err := http.NewRequestWithContext(timeoutContext, http.MethodGet, &quot;https://jsonplaceholder.typicode.com/users&quot;, nil)</pre><p>From this code;</p><blockquote>We’re declaring the timeoutContext and pass in a<em> context.WithTimeout. WithTimeout</em> returns <em>WithDeadline(parent, time.Now().Add(timeout)). </em>Canceling this context releases resources associated with it, so the code should call cancel as soon as the operations running in this Context are complete. In the request, we pass <em>http.NewRequestWithContext</em> and the <em>timeContext</em>. That way, anytime the request exeeds 100 milliseconds before it gets the users, it’s cancelled</blockquote><p>This helps to make your programs more efficient so that they are not doing more work than they need to.</p><h3>Interfaces</h3><p>The key principle of an interface in Go is to provide method signatures for similar types of objects. Go as a programming language doesn’t have classes and inheritance to create and implement object orientation, it uses abstract <a href="https://go.dev/tour/basics/11">types</a> and interfaces to achieve <a href="https://www.geeksforgeeks.org/perl-polymorphism-in-oops/">Polymorphism</a>.</p><h4>How to create interfaces</h4><p>An interface is created using the <em>type</em> keyword followed by the <em>name of the interface</em> and then the <em>interface</em> keyword. You can specify the method signatures inside the curly braces.</p><p>Here’s an example;</p><pre>package main<br><br> type Employee interface {<br>  // method signatures<br> GetName() string<br>}<br></pre><p>To implement an interface, you need to implement all the methods declared in the interface. It’s important to note that Interfaces in Go are implemented <strong>implicitly</strong></p><p>Here’s an example of how interfaces are implemented.</p><pre>package main<br><br>import &quot;fmt&quot;<br><br><br>// declare an interface employee<br>type Employee interface {<br> GetName() string<br>}<br><br>// create a struct<br>type Engineer struct {<br> Name string<br>}<br><br>type Finance struct {<br> Name string<br>}<br><br>// create a method that implements the Employees&#39;s interface<br>func (e *Engineer) GetName() string {<br> return &quot;employee name:&quot; + e.Name<br><br>}<br><br>// create a method that implements the Employee&#39;s interface<br>func (f Finance) GetName() string {<br> return &quot;employee name:&quot; + f.Name<br>}<br><br>// print out the engineer&#39;s details<br>func EmployeeDetails(e Employee) {<br> fmt.Println(e.GetName())<br>}<br><br>func main() {<br> engineer := &amp;Engineer{<br>  Name: &quot;Rebeccah&quot;,<br> }<br> EmployeeDetails(engineer)<br><br> finance := &amp;Finance{<br>  Name: &quot;John Doe&quot;,<br> }<br> EmployeeDetails(finance)<br>}</pre><p>Output:</p><pre>go run main.go<br>employee name: Rebeccah<br>employee name: John Doe</pre><p><strong>Empty Interfaces</strong></p><p>An empty interface is a type of interface that has <strong>zero</strong> methods. Normally in functions, when we pass values to the function parameters, we need to specify the data type of parameters in a function definition.</p><p>However, with an empty interface, we can pass parameters of any data type. For example,</p><pre>var i interface{}<br><br>func getType(i interface{}){<br> fmt.Printf(&quot;Type = %T, value = %v\n&quot;, i, i)<br>}<br><br>func main() {<br> d:= &quot;Golang concepts&quot;<br> getType(d)<br><br> x:= 5<br> getType(x)<br>}</pre><blockquote>Output:</blockquote><pre>go run main.go<br>Type = string, value = Golang concepts<br>Type = int, value = 5</pre><blockquote>Here variable <strong>i </strong>is of <strong>empty interface</strong> type.Function <strong>getType</strong> takes in the <strong>i intaface</strong> and prints out the <strong>type</strong> and <strong>value</strong>. In our func main, we have var <strong>d</strong> which we pass in a <strong>string</strong> Golang concepts then call the <strong>getType</strong> method.</blockquote><p><strong>GoLang Type Assertions</strong></p><p>Now that we’ve seen how we can use empty interfaces, we know that an empty interface can accept any type and number of values. This may often create ambiguity on what data an interface is holding. To remove this, we use<strong> type assertions</strong>.</p><p>Example:</p><pre>func main() {<br> var x interface{}<br><br>// store a string to an empty interface<br> x = &quot;Type assertion&quot;<br><br> // type assertion<br> value := x.(string)<br> fmt.Println(value)<br><br>}</pre><p>Output:</p><pre>go run main.go<br>Type assertion</pre><p>Here, we have this line of code that explicitly states that the data we’re passing is a <strong><em>string</em></strong></p><h4><strong>Why are Interfaces important?</strong></h4><ul><li><strong>Modularity</strong> − They help to make code more modular and easier to maintain by separating the interface from the implementation details.</li><li><strong>Reusability</strong> − Interfaces allow you to write code that can work with any type that satisfies that interface, which means that you can reuse the same code for multiple types.</li><li><strong>Testability</strong> − They make it easier to write testable code by allowing you to create mock implementations of the interface for testing purposes.</li></ul><h4>Conclusion</h4><p>In this article, we’ve discussed how to achieve polymorphism using interfaces in Go. An interface is a collection of method signatures that any type can implement, allowing us to write code that can work with any type that implements an interface, without knowing the underlying type.</p><h4>References</h4><ul><li><a href="https://www.geeksforgeeks.org/perl-polymorphism-in-oops/">https://www.geeksforgeeks.org/perl-polymorphism-in-oops/</a></li><li><a href="https://go.dev/tour/basics/11">https://go.dev/tour/basics/11</a></li><li><a href="https://go.dev/tour/concurrency/1">https://go.dev/tour/concurrency/1</a></li><li><a href="https://pkg.go.dev/context">https://pkg.go.dev/context</a></li><li><a href="https://go.dev/tour/methods/9">https://go.dev/tour/methods/9</a></li></ul><p>I hope you’ve learnt something new/awesome. Feel free to share your feedback, questions, or comments <a href="https://emojipedia.org/nerd-face">🤓</a></p><p>If you liked this article click <a href="https://emojipedia.org/clapping-hands">👏</a> below!</p><p>Happy learning<a href="https://emojipedia.org/nerd-face">🤓</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e24397f7edf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced GoLang Concepts: Channels, Context, and Interfaces.]]></title>
            <link>https://medium.com/@wambuirebeka/advanced-golang-concepts-channels-context-and-interfaces-dc3b71cd0ed8?source=rss-5bd656a64e93------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc3b71cd0ed8</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Rebeccah Wambui]]></dc:creator>
            <pubDate>Wed, 13 Sep 2023 11:54:32 GMT</pubDate>
            <atom:updated>2023-12-06T03:56:51.710Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8P8fbsb7Ywvl_NT2" /><figcaption>Photo by <a href="https://unsplash.com/@dnevozhai?utm_source=medium&amp;utm_medium=referral">Denys Nevozhai</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>In this article, we will cover some advanced GoLang concepts in detail. In Go, these are some of the building blocks. They are tools that you can use to make your code clean, scalable, and maintainable especially when your project grows in complexity.</p><p>It’ll be pretty cool if you open your IDE, and follow the steps, as we learn together! Let’s get into it!</p><h4>C<strong>hannels</strong></h4><p>Channels are fundamental tools for achieving concurrency in Go. They are used to communicate and transfer data between <a href="https://go.dev/tour/concurrency/1">go-routines</a>. The communication is bidirectional by default, which means you can send and receive messages from the same go-routine</p><p><strong>Implementation 👩‍💻</strong></p><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br> dataChan := make(chan string) //adds data to the channel<br> dataChan &lt;- &quot;Hey Champ!&quot;      // gets data from the channel<br><br> c := &lt;- dataChan<br><br> fmt.Println(c)<br>}</pre><p>In this function— ;</p><blockquote>- <em>We’re declaring our channel</em>,<em> </em>dataChan <em>and</em> <em>explicitly stating the data type </em>(String)</blockquote><blockquote>- <em>Send data to the channel</em></blockquote><blockquote><em>- Receiving the data from the channel</em></blockquote><blockquote><em>- Print the data using </em>Println</blockquote><p>If we run this function, we get the following results;</p><pre>fatal error: all goroutines are asleep - deadlock!<br><br>goroutine 1 [chan send]:<br>main.main()<br>        /Users/rebeccahwambui/Beck/golang-concepts/channels/main.go:7 +0x3c<br>exit status </pre><p>The reason why we’re getting a deadlock error is because, by default, if you put data into a channel, you also need to create an exit, this process needs to be done simultaneously.</p><p>Both of these lines;</p><blockquote><em>dataChan := make(chan string)</em></blockquote><blockquote><em>dataChan &lt;- “Hey Champ!&quot;</em></blockquote><p>need to execute simultaneously, we can achieve that by;</p><h4>1. Creating another go-routine;</h4><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br> dataChan := make(chan string) //adds data to the channel<br><br> go func() {    // go-routine that&#39;s running on the background thread<br>  dataChan &lt;- &quot;Hey Champ!&quot;  // gets data from the channel<br> }()<br><br> c := &lt;- dataChan<br><br> fmt.Println(c)<br>}</pre><p>If we run this now, we get results;</p><pre>go run .<br>Hey Champ!</pre><p>We now have the channels running on different go-routines and can be executed simultaneously!</p><h4>2. Creating a Buffered Channel;</h4><p>When we ran our first block of code, we got a <em>deadlock error</em> because our channel didn’t have any space init. Technically, you can create some space by making the channel a <em>Buffered channel.</em></p><h4>What is a buffered Channel?</h4><p>Buffered channels in Golang are used to communicate concurrently executing functions by sending and receiving information from a certain element type for a given capacity.</p><p>They work best when you want to<em> get </em>back data from a set(s) of <a href="https://go.dev/tour/concurrency/1">go-routines</a> or if you want to limit concurrent usage. They are also helpful for managing the amount of work a system has queued up, preventing your program from becoming overwhelmed.</p><p>Implementation 👩‍💻</p><pre>func main() {<br> dataChan := make(chan string, 1) // buffered channel<br><br> dataChan &lt;- &quot;Hey Champ!&quot; //add data to the channel<br> c := &lt;-dataChan // get data from the channel<br><br> fmt.Println(c)<br>}</pre><p>Response;</p><pre>go run .<br>Hey Champ!</pre><blockquote>Note: This is only used to set limited number of data, if we try to add data to the channel without updating the space, you will get a deadlock error, because we’ve explicitly sayed we’re adding only one value to the channel,so the channel only expects a single value.</blockquote><pre>func main() {<br> dataChan := make(chan string, 1)<br><br> dataChan &lt;- &quot;Hey Champ!&quot;<br> dataChan &lt;- &quot;GoLang is awesome!&quot;<br> c := &lt;-dataChan<br><br> fmt.Println(c)<br>}</pre><pre>go run .<br>fatal error: all goroutines are asleep - deadlock!<br><br>goroutine 1 [chan send]:<br>main.main()<br>        <br>exit status 2</pre><p>We’ve gone through the high level of what channels are and how they work. Technically, channels are used in a multi-threading context; used with different go-routines.</p><p>We’ll take a dip-dive at what this looks like in a simple function:</p><p>From this block of code;</p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;math/rand&quot;<br> &quot;sync&quot;<br> &quot;time&quot;<br>)<br><br>func DoWork() int {<br> time.Sleep(time.Second)<br> return rand.Intn(10)<br>}<br><br>func main() {<br> dataChan := make(chan int)<br><br> go func() {           // go-routine that&#39;s running on the background thread<br>  wg := sync.WaitGroup{}<br><br>  for i := 0; i &lt; 10; i++ {<br>   wg.Add(1)<br><br>   go func() {        // go-routine that&#39;s running on the background thread<br>    defer wg.Done()<br>    result := DoWork()<br>    dataChan &lt;- result<br>   }()<br>  }<br><br>  wg.Wait()<br>  close(dataChan)<br> }()<br><br> for x := range dataChan {<br>  fmt.Printf(&quot;%d\n&quot;, x)<br><br> }<br><br>}</pre><pre>$ We create a func DoWork() which returns an int<br><br>func DoWork() int {<br> time.Sleep(time.Second) // sleep for 1 sec<br> return rand.Intn(10) // return a random int from 1 - 100<br>}<br><br>$ In our main fun, we have our unbuffered chan which takes in an int<br>  dataChan := make(chan int)<br><br>$ In our first go-routine,we create a for loop, which for every iteration,<br> of the function, it creates a new go-routine that does the work,<br> and sends the results to the dataChan<br><br>   for i := 0; i &lt; 10; i++ {<br>   wg.Add(1)<br><br>   go func() { // go-routine that&#39;s running on the background thread<br>    defer wg.Done()<br>    result := DoWork()<br>    dataChan &lt;- result // send results to the dataChan<br>   }()<br><br>  }<br><br>$ To prevent the deadlock error, we need to track and wait for <br>  the go-routines to complete the loop. For that,we use the WaitGroup.<br>  For each iteration we add 1 to the WaitGroup<br><br>   for i := 0; i &lt; 10; i++ {<br>   wg.Add(1)<br><br> - In the iteration, we defer wg.Done()<br>  defer wg.Done()<br> <br>- In the end, we wait until all the iterations are done, before we close<br>  the channel<br><br>  wg.Wait()<br>  close(dataChan)<br><br>$ Lastly we print out the results<br><br>  for x := range dataChan {<br>  fmt.Printf(&quot;%d\n&quot;, x)<br><br> }<br> </pre><p>Results:</p><pre>go run .<br>1<br>7<br>7<br>9<br>1<br>8<br>5<br>0<br>6<br>0</pre><p>I hope this is helpful 🙂 Let me know in the comments section. Feel free to share your feedback and questions as well.</p><p>Happy learning 🤓</p><p>You can find Part 2 on Context and Interfaces <a href="https://medium.com/@wambuirebeka/advanced-golang-concepts-channels-context-and-interfaces-part-2-e24397f7edf9">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc3b71cd0ed8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Integrate Slack Notifications Using GoLang]]></title>
            <link>https://medium.com/@wambuirebeka/how-to-integrate-slack-notifications-using-golang-84451aca27e3?source=rss-5bd656a64e93------2</link>
            <guid isPermaLink="false">https://medium.com/p/84451aca27e3</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[slackbot]]></category>
            <dc:creator><![CDATA[Rebeccah Wambui]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 17:15:54 GMT</pubDate>
            <atom:updated>2023-02-20T11:14:48.791Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LelKFeFMxygc2agMMx5mbQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@glvrdru">Maxim</a> on Unsplash</figcaption></figure><p><strong>Overview</strong></p><p>This article is a high-level walkthrough on how you can integrate slack notifications using GoLang. It’s pretty straightforward, let’s get started!</p><p><strong>Step 1:</strong></p><p>In your config.yml or .env file, add the following configs.</p><pre>slack:<br>  slackToken: &lt;your slack token&gt;<br>  slackChannelID: &lt;your channelID&gt;</pre><p>If you’re using a config file, add this to your config.go</p><pre>type slackConfig struct {<br> SlackToken     string `mapstructure:&quot;slackToken&quot;`<br> SlackChannelID string `mapstructure:&quot;slackChannelID&quot;`<br>}</pre><p>As part of the setup, we need to initialize slack using the init() function</p><blockquote>If you’re new to go, an init() function serves some specific purposes such as to initialize a specific state of the application. This function is meant to run before any other piece of code — even before the <em>main()</em> function. To read more about the init() function, check <a href="https://www.developer.com/languages/inti-function-golang/">here</a>.</blockquote><p>In your application’s entry point, add this piece of code</p><pre>func initSlack(cfg *utils.Config) *utils.Slack {<br> return &amp;utils.Slack{<br>  SlackClient: slack.New(cfg.Slack.SlackToken),<br>  ChannelID:   cfg.Slack.SlackChannelID,<br> }<br>}<br><br>slack := initSlack(cfg)<br> if err != nil {<br>  log.Err(err).Msg(&quot;error reading slack credentials from config&quot;)<br> }</pre><p>In this code, we’re initializing our slack client.</p><blockquote>Our function <em>initSlack()</em> takes in the config and returns our slack object.</blockquote><blockquote><em>slack.New() </em>New builds a slack client from the provided token and options.</blockquote><blockquote>Then we’ll log an error if any</blockquote><p>Hurrah! all set up 😃</p><p><strong>Step 2</strong></p><p>Now that we’re all set up and good to go, we can start writing our logic. In your utils folder, create a file — slack.go</p><pre>package utils<br><br>import (<br> &quot;github.com/rs/zerolog/log&quot;<br> &quot;github.com/slack-go/slack&quot;<br>)<br><br>type Slack struct {<br> SlackClient *slack.Client<br> ChannelID   string<br>}<br><br>func (s *Slack) SendSlackMessage(message string) error {<br> ChannelID, timestamp, err := s.SlackClient.PostMessage(s.ChannelID, slack.MsgOptionText(message, false))<br> if err != nil {<br>  return err<br> }<br> log.Info().Str(&quot;message&quot;, message).Msgf(&quot;Message sent successfully to %s channel at %s&quot;, ChannelID, timestamp)<br> return nil<br>}</pre><p>The struct takes in the slackClient and the channelID (<a href="https://help.socialintents.com/article/148-how-to-find-your-slack-team-id-and-slack-channel-id">from your slack channel</a>)</p><blockquote>Our func sendSlackMessage takes in a string and returns an error if any.</blockquote><blockquote>SlackClient has a module PostMessage which takes in the channelID, and a message of type string. Slack PostMessage sends a message to a channel. Message is escaped by default according to <a href="https://api.slack.com/docs/formatting">https://api.slack.com/docs/formatting</a> Use <a href="http://davestevens.github.io/slack-message-builder/">http://davestevens.github.io/slack-message-builder/</a> to help crafting your message.</blockquote><blockquote>We then check for an error, if any, we log the error. You can post the error on sentry <em>(nice to have).</em></blockquote><blockquote>If the request to slack was successful, we log.info() a successful message.</blockquote><p><strong>Step 3:</strong></p><p>Based on your use case, determine where you want to call your sendSlackMessage() function and add this</p><pre>v.Slack.SendSlackMessage(fmt.Sprintf(&quot;[%s] :information_source: &lt;!channel&gt; *Unprocessable Entity, invalid payload: %s&quot;, v.Cfg.App.Environment, payload))</pre><p><strong>Nice to have</strong>: Include your environment and payload for easy debugging.</p><p>That’s pretty much it, feel free to ask questions, happy to respond!🤩</p><h4><strong>More Resources:</strong></h4><p><a href="https://help.socialintents.com/article/148-how-to-find-your-slack-team-id-and-slack-channel-id">How to find your channelID on slack</a></p><p><a href="https://www.developer.com/languages/inti-function-golang/">Deep dive into GoLang init() function</a></p><p>Happy Coding!🤩</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84451aca27e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Deploy A Service On Kubernetes Using Minikube ]]></title>
            <link>https://medium.com/@wambuirebeka/how-to-deploy-an-service-on-kubernetes-using-minikube-e5e78a716f41?source=rss-5bd656a64e93------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5e78a716f41</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[minikube]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Rebeccah Wambui]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 17:22:48 GMT</pubDate>
            <atom:updated>2023-02-09T15:54:45.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*PC-UwC578eCEPYDE" /><figcaption><a href="https://unsplash.com/photos/woWf_VJ7dNs">Unsplash</a> photo by <a href="https://unsplash.com/@billjelen">Bill Jelen</a></figcaption></figure><p>Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management.</p><p>I will take you through a few steps on how you can deploy a simple service on Kubernetes using Minikube.</p><h4><strong>What is Minikube?</strong></h4><p>Minikube is <strong>a lightweight Kubernetes implementation that creates a Virtual Machine on your local machine and deploys a simple cluster containing only one node. </strong>Minikube is available for Linux, macOS, and Windows systems.</p><h3>Installing Minikube — On Linux</h3><pre>curl -LO &lt;https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64&gt;<br> sudo install minikube-linux-amd64 /usr/local/bin/minikube</pre><h3>Starting your Cluster.</h3><p>Use <em>minikube start</em> to start your cluster.</p><h3>Interacting with your cluster</h3><p>Use minikube kubectl --get po -A to interact with your cluster</p><p>Use minikube dashboard to access the dashboard</p><h3>Deploying an Application</h3><p>Let’s create a simple deployment and expose it on port 8080, using the following command.</p><pre>kubectl create deployment hello-minikube --image=[k8s.gcr.io/echoserver:1.4](&lt;http://k8s.gcr.io/echoserver:1.4&gt;)<br>kubectl expose deployment hello-minikube --type=NodePort --port=808</pre><p>Great!😀 Your deployment has been created successfully. Now to run your deployment, run kubectl get services hello-minikube</p><h3>Load-balancer Deployments</h3><p>Load balancing refers to the process of distributing a set of tasks over a set of resources, with the aim of making their overall processing more efficient.</p><ul><li>To access the load balancer deployments use minikube tunnel command.</li></ul><pre>kubectl create deployment balanced --image=[k8s.gcr.io/echoserver:1.4](&lt;http://k8s.gcr.io/echoserver:1.4&gt;)<br>kubectl expose deployment balanced --type=LoadBalancer --port=8080</pre><ul><li>To start the tunnel to create a routable IP for the ‘balanced’ deployment:</li></ul><pre>minikube tunnel</pre><ul><li>To find the routable IP, run this command and examine the EXTERNAL-IP</li></ul><pre>kubectl service balanced</pre><p>Great! 😀 Your deployment is now available on &lt;EXTERNAL-IP&gt;:8080</p><h3>Services.</h3><p>A service in K8s enables the communication between various components within or outside the application.</p><h3>Types of services.</h3><ul><li>Node port services.</li></ul><p>It will expose the service on a static port on the deployed node. This service can be accessed outside the cluster using a NodeIP: NodePort.</p><ul><li>Cluster IP.</li></ul><p>It exposes the service within the Kubernetes cluster. This service is only accessed within the cluster.</p><ul><li>Load balancer.</li></ul><p>Exposes the Service externally using a cloud provider’s load balancer, this creates a Public IP on the Cloud provider.</p><h3>Creating a service.</h3><p>To create a service, you must have the following:</p><ul><li>A Kubernetes cluster that has at least 1 worker node.</li></ul><p>To access a cluster type this command. kubectl config view</p><h3>Steps for creating a service.</h3><ul><li>Create a deployment YAML file.</li></ul><pre>apiVersion: apps/v1<br>kind: Deployment</pre><pre>metadata:</pre><pre>name: nginx</pre><pre>spec:</pre><pre>strategy:</pre><pre>type: Recreate</pre><pre>selector:</pre><pre>matchLabels:</pre><pre>app: nginx</pre><pre>replicas: 3</pre><pre>template:</pre><pre>metadata:</pre><pre>labels:</pre><pre>app: nginx</pre><pre>spec:</pre><pre>containers:</pre><pre>- name: nginx</pre><pre>image: nginx</pre><pre>ports:</pre><pre>- containerPort: 80</pre><p>To create the deployment, type the following command.</p><p>kubectl create -f my-deployment.yml</p><p>You can get the details of deployment, replica set, and pod using the following commands:</p><p>kubectl get deployment| grep nginx</p><p>kubectl get replicaset| grep nginx</p><p>kubectl get pods | grep nginx</p><ol><li>Create a service with a yml file.</li></ol><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: nginx<br>  namespace: default<br>  labels:<br>    app: nginx<br>spec:<br>  externalTrafficPolicy: Local<br>  ports:<br>  - name: http<br>    port: 80<br>    protocol: TCP<br>    targetPort: 80<br>  selector:<br>    app: nginx<br>  type: NodePort</pre><p>To execute a service, execute the following command. Kubectl create -f my-service.yml</p><p>Get the details of the service and check for the NodePort on which the service will be available using the following commands:</p><p>kubectl get service | grep nginxGet the NodePort</p><p>kubectl describe service nginxGet the details of the service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5e78a716f41" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>