Image for post
Image for post

Preface

Interfaces is a very important feature in Go. It is a key to implement polymorphism and dependency injection in Go. In spite of its importance, there are some serious arguments about the best practice of Go interfaces, which may lead to another little-endian v.s. big-endian war in the future. The purpose of this blog to is to discuss these arguments in a peaceful way and find a way to avoid this potential war (if possible).

Introduction to Go Interfaces

The following shows an example of Go interface:

From the above example, you can see that:


Image for post
Image for post

Preface

Encapsulation, as known as information hiding, is a key aspect of object-oriented programming. An object’s field or method is said to be encapsulated if it is inaccessible to users of the object. Unlike classical objected programming languages like Java, Go has very specific encapsulation rules. This blog is going to explore these “interesting” rules.

Encapsulation Rules in Go

Go has only one rule to set up encapsulation: capitalized identifiers are exported from the package where they are defined and un-capitalized ones are not. A field/method of a struct/interface is exported only when the names of the field/method and struct/interface are both capitalized (AND condition).

Let’s go through an example to discuss the difference between Java and Go in terms of encapsulation. …


Image for post
Image for post

Preface

What is included in this blog:

prerequisites

Go Modules

Go Modules is an experimental opt-in feature in Go 1.11 with the plan of finalizing feature for Go 1.13. The definition of a Go module from this proposal is “a group of packages that share a common prefix, the module path, and are versioned together as a single unit”. …


Image for post
Image for post

What Is nil in Go

nil in Go has several meanings:

Using nil as Zero Values

nil represents zero values (and default values) of some types in Go.

Example:

Using nil in Comparison

Two nil Values of Two Different Types Are Not Comparable

Example:

This code will fail to compile as they are trying to compare nil values of two different types. …


Image for post
Image for post

Preface

This series of blogs is an introduction to Kubernetes (k8s) explaining its basic concepts and commonly-used components for building and deploying applications in Kubernetes. The purpose of this series of blogs is for you to quickly learn the basic knowledge of Kubernetes in an hour. However, I highly recommend you check official Kubernetes documentation if you want to dive deeply into Kubernetes.

Index

Reference


Kubernetes is a portable, extensible system for running and coordinating containerized workloads and services across a cluster of machines. It is designed to manage the life cycle of containerized applications with the guarantee of stability, scalability, and high availability.

The following picture shows a Kubernetes cluster running on Google Kubernetes Engine (GKE):

Image for post
Image for post

From the picture, you can see that:


Preface

This blog talks about the basic knowledge of Kubernetes Pods. But before exploring Kubernetes Pods, let us first go through what a Docker container is as it is the major container technology that we use to run our applications.

Docker Containers

Docker is an open platform that allows you to package and run applications in a loosely isolated environment called a container. A Docker container is a runnable instance of a Docker image and a Docker read-only template for creating a Docker container. In other words, we need to construct a Docker image before running a Docker container. …


Prerequisites

I recommend you know the basic knowledge of Kubernetes Pods before reading this blog. You can check this blog for details about Kubernetes Pods.

What Is A Deployment

Normally, when working with Kubernetes, rather than directly managing a group of replicated Pods, you would like to leverage higher-level Kubernetes objects & workloads to manage those Pods for you. Kubernetes Deployments is one of the most common workloads in Kubernetes that provides flexible life cycle management for a group of replicated Pods.

A Deployment is a Kubernetes object that provides declarative updates, such as scaling up/down, rolling updates, and rolling back, for a group of identical Pods. …


prerequisites

I recommend you know the basic knowledge of Kubernetes Pods before reading this blog. You can check this blog for details about Kubernetes Pods.

What Is A StatefulSet

StatefulSet is a Kubernetes object designed to manage stateful applications. Like a Deployment, a StatefulSet scales up a set of pods to the desired number that you define in a config file. Pods in a StatefulSet runs the same containers that are defined in the Pod spec inside the StatefulSet spec. Unlike a Deployment, every Pod of a StatefulSet owns a sticky and stable identity. …


What Is A Kubernetes Service

A Service is a Kubernetes object that exposes a set of Pods as a network service. Moreover, it provides a service discovery mechanism that dynamically adds or removes IP addresses of Pods to its endpoint list based on the creation or deletion of these Pods.

Service Types

Kubernetes provides many types of services but here only those frequently used ones are introduced. You can check this document for more details. Here only commonly used Services will be introduced.

LoadBalancer

A LoadBalancer exposes a set of Pods externally. A LoadBalancer is an L4 (Layer 4) load balancer, which means it can only utilize the information at the transport layer (Layer 4) to determine how to distribute client requests across a group of Pods. …

About

Aaron Zhuo

A software engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store