Download Full (Ebook) Traefik API Gateway for Microservices: With Java and Python Microservices Deployed in Kubernetes by Rahul Sharma, Akshay Mathur ISBN 9781484263754, 9781484263761, 1484263758, 1484263766 PDF All Chapters
Download Full (Ebook) Traefik API Gateway for Microservices: With Java and Python Microservices Deployed in Kubernetes by Rahul Sharma, Akshay Mathur ISBN 9781484263754, 9781484263761, 1484263758, 1484263766 PDF All Chapters
com
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
ebooknice.com
ebooknice.com
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master
the SAT Subject Test: Math Levels 1 & 2) by Arco ISBN
9780768923049, 0768923042
https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
Traefik API
Gateway for
Microservices
With Java and Python Microservices
Deployed in Kubernetes
—
Rahul Sharma
Akshay Mathur
Traefik API Gateway
for Microservices
With Java and Python
Microservices Deployed
in Kubernetes
Rahul Sharma
Akshay Mathur
Traefik API Gateway for Microservices
Rahul Sharma Akshay Mathur
Patpargunj, Delhi, India Gurgaon, Haryana, India
v
Table of Contents
Traefik�����������������������������������������������������������������������������������������������������������������21
Installation�����������������������������������������������������������������������������������������������������23
Traefik Command Line�����������������������������������������������������������������������������������24
Traefik API������������������������������������������������������������������������������������������������������26
Traefik Dashboard�����������������������������������������������������������������������������������������28
Summary������������������������������������������������������������������������������������������������������������29
vi
Table of Contents
vii
Table of Contents
Deploy Pet-Clinic�����������������������������������������������������������������������������������������167
Pet-Clinic UI�������������������������������������������������������������������������������������������������171
Configure Gateway��������������������������������������������������������������������������������������������173
Service Details��������������������������������������������������������������������������������������������177
Circuit Breaker���������������������������������������������������������������������������������������������179
Retries���������������������������������������������������������������������������������������������������������182
Throttling�����������������������������������������������������������������������������������������������������185
Canary Deployments�����������������������������������������������������������������������������������188
Summary����������������������������������������������������������������������������������������������������������190
Index�������������������������������������������������������������������������������������������������247
viii
About the Authors
Rahul Sharma is a seasoned Java developer
with over 15 years of industry experience.
In his career, he has worked with companies
of various sizes, from enterprises to start-
ups. During this time, he has developed and
managed microservices on the cloud (AWS/
GCE/DigitalOcean) using open source
software. He is an open-source enthusiast and
shares his experience at local meetups.
He has co-authored Java Unit Testing with JUnit 5 (Apress, 2017) and
Getting Started with Istio Service Mesh (Apress, 2019).
ix
About the Technical Reviewer
Brijesh is currently working as a lead
consultant. He has more than ten years of
experience in software development and
providing IT solutions to clients for their
on-premise or cloud-based applications,
spanning from monoliths to microservice-
based architecture.
xi
Acknowledgments
This book would not have been possible without the support of many
people. I would like to take this opportunity and express my gratitude to
each of them.
I would like to thank Divya Modi for believing in the project and
making it work. She has been instrumental in starting the project.
Moreover, during the project, her editorial support provided a constant
push throughout the process. It would have been difficult to deliver the
project without your support.
I would like to thank Celestin Suresh John for providing me this
wonderful opportunity. Your guidance made sure that we got the correct
path outlined from the start.
I would like to thank Brijesh Pant and Laura C. Berendson for sharing
valuable feedback. Your advice has helped to deliver the ideas in a better
manner.
I would also like to thank my co-author Akshay Mathur for his
knowledge and support. Your experience and willingness have made this
a successful project. The brainstorming sessions we had helped to express
the ideas.
I wish to thank my parents, my loving and supportive wife, Swati,
and my son, Rudra. They are a constant source of encouragement and
inspiration. Thanks for providing the time and listening to my gibberish
when things were not working according to the plan.
Lastly, I would like to thank my friends, who have been my source
of knowledge. The discussion we had often helped me to deliberate on
various topics. Often our debates have provided the testbed for evaluations.
—Rahul Sharma
xiii
Acknowledgments
xiv
Introduction
Microservice architecture has brought dynamism to the application
ecosystem. New services are built and deployed while older ones are
deprecated and removed from the enterprise application estate. But
front-end load balancers haven’t been able to adapt to the components
in the enterprise architecture. Most current load balancers have a static
configuration. They require configuration updates as the application
landscape changes. Thus, there are operational complexities when
working with microservices. These are a few of the challenges of getting
a microservices-based solution to work. The dynamic nature of the
ecosystem requires dynamic tools that can autoconfigure themselves.
Traefik bases its foundations on the dynamic nature of the
Microservice architecture. It has built first-class support for service
discovery, telemetry, and resiliency. It is a modern HTTP reverse proxy
and load balancer that eases microservices deployment. Its integration has
been great, with many existing tools.
The book covers Traefik setup, basic workings, and integration with
microservices. It is intended for developers, project managers, and DevOps
personnel interested in solutions for their operational challenges.
The book is not specific to any programming language, even though all
the examples use Java or Python.
xv
CHAPTER 1
Introduction to Traefik
Over the last couple of years, microservices have become a mainstream
architecture paradigm for enterprise application development. They have
replaced the monolithic architecture of application development, which
was mainstream for the past couple of decades. Monolithic applications
are developed in a modular architecture. This means that discrete logic
components, called modules, are created to segregate components based
on their responsibility. Even though an application consisted of discrete
components, they were packaged and deployed as a single executable.
Overall, the application has very tight coupling. Changes to each of these
modules can’t be released independently. You are required to release a
complete application each time.
A monolithic architecture is well suited when you are building
an application with unknowns. In such cases, you often need quick
prototyping for every feature. Monolithic architecture helps in this case,
as the application has a unified code base. The architecture offers the
following benefits.
• Simple to develop.
2
Chapter 1 Introduction to Traefik
M
icroservice Architecture
Microservice architecture is an alternative to the monolithic architecture
(see Figure 1-1). It converts the single application to a distributed system
with the following characteristics.
3
Chapter 1 Introduction to Traefik
4
Chapter 1 Introduction to Traefik
5
Chapter 1 Introduction to Traefik
Agility
This is one of the biggest driving factors for an organization adopting the
microservices architecture. Organizations become more adaptive, and
they can respond more quickly to changing business needs. The loose
coupling offered by the architecture allows accelerated development.
Small, loosely coupled services can be built, modified, and tested
individually before deploying them in production. The model dictates
small independent development teams working within their defined
boundaries. These teams are responsible for maintaining high levels of
software quality and service availability.
Innovation
The microservice architecture promotes independent small development
teams supporting each service. Each team has ownership within their
service boundary. They are not only responsible for development but also
for operating the service. The teams thus adopt a lot of automation and
tools to help them deliver these goals. These high-level goals drive the
engineering culture within the organization.
6
Chapter 1 Introduction to Traefik
Resilience
Fault isolation is the act of limiting the impact of a failure to a limited
subsystem/component. This principle allows a subsystem to fail as long
as it does not impact the complete application. The distributed nature of
microservice architecture offers fault isolation, a principal requirement
to build resilient systems. Any service which is experiencing failures
can be handled independently. Developers can fix issues and deploy
new versions while the rest of the application continues to function
independently.
Resilience, or fault tolerance, is often defined as the application’s
ability to function properly in the event of a failure of some parts.
Distributed systems like microservices are based on various tenets
like circuit breaking, throttling to handle fault propagation. This is an
important aspect; if done right, it offers the benefits of a resilient system.
But if this is left unhandled, it leads to frequent downtime due to failures
cascading. Resilience also improves business agility as developers can
release new services without worrying about system outages.
Scalability
Scalability is defined as the capability of a system to handle the growth
of work. In a monolith, it is easy to quantify the system scalability.
In a monolithic system, as the load increases, not all subsystems get
proportionally increased traffic. It is often the case that some parts of the
7
Chapter 1 Introduction to Traefik
system get more traffic than others. Thus, the overall system performance
is determined by a subset of the services. It is easier to scale a monolithic
system by adding more hardware. But at times, this can also be difficult as
different modules may have conflicting resource requirements. Overall an
overgrown monolith underutilizes the hardware. It often exhibits degraded
system performance.
The decoupling offered by microservices enables the organization
to understand the traffic that each microservice is serving. The
divide and conquer principle helps in improving the overall system
performance. Developers can adopt appropriate task parallelization
or clustering techniques for each service to improve the system
throughput. They can adopt appropriate programming languages and
frameworks, fine-tuned with the best possible configuration. Lastly,
hardware can be allocated by looking into service demand rather than
scaling the entire ecosystem.
Maintainability
Technical debt is a major issue with monolithic systems. Overgrown
monoliths often have parts that are not well understood by the complete
team. Addressing technical debt in a monolith is difficult as people often
fear of breaking any of the working features. There have been cases where
unwanted dead code was made alive by addressing technical debt on a
particular monolith.
Microservice architecture helps to mitigate the problem by following
the principle of divide and conquer. The benefits can be correlated with
an object-oriented application design where the system is broken into
objects. Each object has a defined contract and thus leads to improved
maintenance of the overall system. Developers can unit test each of
the objects being refactored to validate the correctness. Similarly,
microservices created around a business context have a defined contract.
These loosely coupled services can be refactored and tested individually.
8
Chapter 1 Introduction to Traefik
Developers can address the technical debt of the service while validating
the service contract. Adopting microservices is often referred to as a
monolith’s technical debt payment.
You have looked at the advantages of Microservice architecture. But
the architecture also brings a lot of challenges. Some challenges are due to
the distributed nature of the systems, while others are caused by diversity
in the application landscape. Services can be implemented in different
technologies and scaled differently. There can be multiple versions of the
same service serving different needs. Teams should strategize to overcome
these challenges during application design and not as an afterthought.
Application deployment is one such important aspect. Monoliths have
been deployed on a three-tier model. But the same model does not work
well with microservices. The next section discusses the changes required
in the deployment model.
n-Tier Deployment
n-tier deployment is a design implementation where web applications
are segregated into application presentation, application processing, and
data management functions. These functions are served by independent
components known as tiers. The application tiers allow segregation of
duties. All communication is linear across the tiers. Each tier is managed
by its own software subsystem. The n-tier deployment offers the benefit of
improved scalability of the application. Monolithic applications are usually
deployed as three-tiers (see Figure 1-2) applications.
9
Chapter 1 Introduction to Traefik
10
Chapter 1 Introduction to Traefik
11
Chapter 1 Introduction to Traefik
F our-Tier Deployment
The three-tier deployment works in line with monolith applications.
The monolith is usually the application tier. But with microservices, the
monolith is converted into several services. Thus the three-tier deployment
model is not good enough to handle microservice architecture. It needs
the following four-tier deployment model (see Figure 1-3).
For each request, the gateway layer receives data from all
the underlying services and sends back a single aggregated
response. It has to handle different scenarios like role-based
access, delayed responses, and error responses. These
behaviors make it easier for the service tier. The service tier
can focus only on the business requirements.
12
Chapter 1 Introduction to Traefik
13
Chapter 1 Introduction to Traefik
G
ateway Characteristics
A gateway is the point of entry for all user traffic. It is often responsible for
delegating the requests to different services, collate their responses, and
send it back to the user. Under microservice architecture, the gateway must
work with the dynamic nature of the architecture. The following sections
discuss the different characteristics of the gateway component.
14
Chapter 1 Introduction to Traefik
PROTOCOLS
15
Chapter 1 Introduction to Traefik
Dynamic Configuration
In a monolith application, you know the location of our backend
application. The location does not change often, and more instances of the
application are not created at runtime. Since most servers are known, it is
easier to provide these details in a static configuration file.
But in a microservices application, that solution does not work. The
first challenge arises from the number of microservices. Usually, there are
limited services at the start. But as the system grows, people realize there
can be multiple fine-grained services for every business function. Often
the number can grow to a couple of hundred services. It is a daunting task
to allocate a static address to each of these services and maintain the same
updates in a static file.
The second challenge arises from scalability offered by microservices.
Services can be replicated during load times. These services are removed
when the load subsides. This runtime behavior of microservices gets
multiplied by the number of services in the ecosystem. It is impossible to
keep track of all these changes in a static configuration file.
To solve discovery issues, a microservice architecture advocates a
service registry. It is a database containing the network locations of service
instances. The service registry needs to be updated in near real time. It
needs to reflect the new locations as soon as they are available. A service
registry needs to have high availability. Consequently, it consists of a
cluster of nodes that replicate data to maintain consistency.
The following are the most widely used service registry providers.
16
Exploring the Variety of Random
Documents with Different Content
from thirty to fifty or a hundred birds streaming from or towards the
berg, and we could not doubt that we were approaching a very
populous breeding-colony. But we had been told of millions of
brooding birds, and as yet we could see nothing of such numbers. At
length, after we had rowed round a projecting ridge, the Nyke lay
before us. In the sea, all around, were black points, at the foot of the
hill white ones. The former were without order or regularity, the latter
generally in rows, or sharply defined troops; the one set consisted of
razor-bills swimming, with head, throat, and neck above the water,
the others were the same birds sitting on the hill with their white
breasts turned towards the sea. There were certainly many
thousands, but not millions.
After we had landed at the opposite island and refreshed ourselves
in the house of the proprietor of the Nyke, we crossed over to it, and
choosing a place round which the seething waves did not surge too
violently, we sprang out on the rock and climbed quickly up to the turf
which covers the whole Nyke, with the exception of a few protruding
peaks, ledges, and angles. There we found that the whole turf was
so pierced with nest-hollows something like rabbit holes, that on the
whole hill not a single place the size of a table could be found free
from such openings. We made our way upwards in a spiral,
clambering rather than walking to the top of the berg. The
undermined turf trembled under our feet, and from every hole there
peeped, crept, glided, or flew out birds rather larger than pigeons,
slate-coloured on the upper part of the body, dazzlingly white on
breast and belly, with fantastic bills and faces, short, narrow, pointed
wings, and stumpy tails. Out of every hole they appeared and even
out of the fissures and clefts in the rocks. Whichever way we turned
we saw only birds, heard only the low droning noise of their
combined weak cries. Every step onwards brought new flocks out of
the bowels of the earth. From the berg down to the sea, from the sea
up to the berg there flew swarms innumerable. The dozens became
hundreds, the hundreds became thousands, and hundreds of
thousands sprang incessantly from the brown-green turf. A cloud not
less thick than that over the holm enveloped us, enveloped the
island, so that it—magically indeed, but in a way perceptible by the
senses—seemed transformed into a gigantic bee-hive, round which
not less gigantic bees, humming and buzzing, hovered and fluttered.
The farther we went, the more magnificent became the spectacle.
The whole hill was alive. Hundreds of thousands of eyes looked
down upon us intruders. From every hole and corner, from every
peak and ledge, out of every cleft, burrow, or opening, they hurried
forth, right, left, above, beneath; the air, like the ground, teemed with
birds. From the sides and from the summit of the berg thousands
threw themselves like a continuous cataract into the sea in a throng
so dense that they seemed to the eye to form an almost solid mass.
Thousands came, thousands went, thousands fluttered in a
wondrous mazy dance; hundreds of thousands flew, hundreds of
thousands swam and dived, and yet other hundreds of thousands
awaited the footsteps which should rouse them also. There was such
a swarming, whirring, rustling, dancing, flying, and creeping all about
us that we almost lost our senses; the eye refused duty, and his
wonted skill failed even the marksman who attempted to gain a prize
at random among the thousands. Bewildered, hardly conscious, we
pushed on our way until at length we reached the summit. Our
expectation here at last to regain quietness, composure, and power
of observation, was not at once realized. Even here there was the
same swarming and whirring as further down the slope, and the
cloud of birds around us was so thick that we only saw the sea dimly
and indefinitely as in twilight. But a pair of jerfalcons, who had their
eyrie in a neighbouring precipice, and had seen the unusual bustle,
suddenly changed the wonderful scene. The razor-bills, guillemots,
and puffins were not afraid of us; but on the appearance of their well-
known and irresistible enemies, the whole cloud threw themselves
with one accord, as at the command of a magician, into the sea, and
the outlook was clear and free. Innumerable black points, the heads
of the birds swimming in the sea, stood out distinctly from the water,
and broke up the blue-green colouring of the waves. Their number
was so great that from the top of the berg, which was over three
hundred feet high, we could not see where the swarm ended, could
not discover where the sea was clear from birds. In order to make a
calculation, I measured out a small square with my eye, and began
to count the points in it. There were more than a hundred. Then I
endeavoured mentally to place several similar squares together, and
soon came to thousands of points. But I might have imagined many
thousands of such squares together and yet not exhausted the
space covered by birds. The millions of which I had been told were
really there. This picture of apparent quiet only lasted for a few
moments. The birds soon began to fly upwards again, and as before,
hundreds of thousands rose simultaneously from the water to
ascend the hill, as before a cloud formed round it, and our senses
were again bewildered. Unable to see, and deafened by the
indescribable noise about me, I threw myself on the ground, and the
birds streamed by on all sides. New ones crept constantly out of their
holes, while those we had previously startled now crept back again;
they settled all about me, looking with comical amazement at the
strange form among them, and approaching with mincing gait so
close to me that I attempted to seize them. The beauty and charm of
life showed themselves in every movement of these remarkable
birds. With astonishment I saw that even the best pictures of them
are stiff and cold, for I remarked in their quaint forms a mobility and
liveliness with which I had not credited them. They did not remain
still a single instant, their heads and necks at least were moved
incessantly to all sides, and their contours often showed most
graceful lines. It seemed as though the inoffensiveness with which I
had given myself up to observing them, had been rewarded by
unlimited confidence on their part. The thousands just about me
were like domestic birds; the millions paid me no more attention than
if I had been one of themselves.
I spent eighteen hours on this bird-berg in order to study the life of
the auks.[4] When the midnight sun stood large and blood-red in the
sky and cast its rosy light on the sides of the hill there came the
peace which midnight brings even in the far North. The sea was
deserted; all the birds which had been fishing and diving in it had
flown up to the berg. There they sat wherever there was room to sit
in long rows of tens, of hundreds, of hundreds of thousands, forming
dazzling white lines as all, without exception, sat facing the sea.
Their ‘arr’ and ‘err’, which had deafened our ears notwithstanding
the weakness of the individual voices, were silent now, and only the
roar of the surf breaking on the rocks far below resounded as before.
Not till the sun rose again did the old bewildering bustle begin anew,
and as we at length descended the hill by the way we had climbed it,
we were once more surrounded by a thick cloud of startled birds.
It is not because of their enormous numbers alone that the auks are
so fascinating; there is much that is attractive in their life and habits.
During the brooding time their social virtues reach an extraordinary
height. Till the beginning of that season they live entirely on the open
sea, defying the severest winter and the wildest storms. Even in the
long night of winter very few of them forsake their northern home, but
they range, in flocks of hundreds and thousands, from one fishing-
ground to another, finding all the open spaces among the ice as
unfailingly as they do other promising feeding-grounds in the open
sea. But when the sun reappears they are animated by one feeling—
love, by one longing—to reach as soon as possible the hill where
their own cradle stood. Then somewhere about Easter-time they all
set out, swimming more than flying, for the bird-berg. But among the
auks there are more males than females, and not every male is
fortunate enough to secure a wife. Among other birds such a
disproportion gives rise to ceaseless strife, yet among these auks
peace is not disturbed. The much-to-be-pitied beings whom, making
use of a human analogy, we may call bachelors, migrate to the berg
as well as the fortunate pairs, who coquette and caress by the way;
they fly up with these to the heights and accompany them on their
hunting expeditions to the surrounding sea. As soon as the weather
permits, the pairs begin to get the old holes in order; they clear them
out, deepen them, enlarge their chambers, and, if necessary, hollow
out a new brooding-place. As soon as this has been done the female
lays, on the bare ground at the further end of the hollowed-out
brooding-chamber, a single very large, top-shaped, brightly-spotted
egg, and begins to brood alternately with the male. The poor
bachelors have a sad time of it now. They, too, would dearly like to
take parental cares upon themselves if they could only find a mate
who would share them. But all the females are appropriated, and
wooing is in vain. So they resolve to give practical proof of their
good-will, at least in so far that they force themselves on the
fortunate pair as friends of the family. In the hours about midnight,
when the female broods on the nest, they sit with the male as he
keeps watch before it, and, when the male relieves his mate that she
may fish in the sea, they mount guard in his stead. But when both
parents visit the sea at once the bachelors hasten to reap some
reward for their faithfulness. Without delay they thrust themselves
into the interior of the cavity, and sit for the time upon the forsaken
egg. The poor birds who are condemned to celibacy want at least to
brood a little! This unselfish devotion has one result for which men
might envy the auks—there are no orphans on these bird-bergs.
Should the male of a pair come to grief, his widow immediately
consoles herself with another mate, and in the rarer case of both
parents losing their lives at once the good-natured supernumeraries
are quite ready to finish hatching the egg and to rear the young one.
The young ones differ materially from those of the ducks and gulls.
They are ‘altrices’, not ‘præcoces’ as the ornithologists say;[5] in
plain language, they are not ready for active life as soon as they are
hatched. In a dress of thick gray down the young auk slips from the
egg in which it awakes to life, but it must spend many weeks in the
hole before it is ready to attempt its first flight to the sea. This first
flight is always a hazardous undertaking, as is proved by the
countless dead bodies on the cliffs at the foot of the berg. The young
bird, nervously using its unpractised legs, hardly less timidly its
newly-developed wings, follows its parents as they lead the way
down the hill towards some place from which the leap into the sea
may be attempted with as little danger as possible. On a suitable
ledge the parents often remain a long time with their young one
before they can induce it to take a spring. Both father and mother
persuade it coaxingly; the little one, usually obedient like all young
birds, pays no heed to their commands. The father throws himself
into the sea before the eyes of his hesitating offspring; the
inexperienced young one remains where he was. More attempts,
more coaxing, urgent pressure: at length he risks the great leap and
plunges like a falling stone deep into the sea; then, unconsciously
obeying his instincts, he works his way to the surface, looks all
around over the unending sea, and—is a sea-bird who thenceforth
shuns no danger.
Different again is the life and activity on the bergs chosen as
brooding-places by the kittiwakes. Such a hill is the promontory
Swärtholm, high up in the north between the Laxen and the
Porsanger fjord, not far from the North Cape. I knew well how these
gulls appear on their brooding-places. Faber, with his excellent
knowledge of the birds of the far North, has depicted it, as usual, in a
few vivid words:
“They hide the sun when they fly, they cover the skerries when they
sit, they drown the thunder of the surf when they cry, they colour the
rocks white when they brood.” I believed the excellent Faber after I
had seen the eider-holms and auk-bergs, and yet I doubted, as
every naturalist must, and therefore I ardently desired to visit
Swärtholm for myself. An amiable Norseman with whom I became
friendly, the pilot of the mail steamer by which I travelled, readily
agreed to row me over to the breeding-place, and we approached
the promontory late one evening. At a distance of six or eight
nautical miles we were overtaken by flocks of from thirty to a
hundred, sometimes even two hundred kittiwakes flying to their
nesting-place. The nearer we approached to Swärtholm the more
rapid was the succession of these swarms, and the larger did they
become. At last the promontory became visible, a rocky wall about
eight hundred yards long, pierced by innumerable holes, rising
almost perpendicularly from the sea to a height of from four hundred
and fifty to six hundred feet. It looked gray in the distance, but with a
telescope one could discern innumerable points and lines. It looked
as though a gigantic slate had been scratched all over with all sorts
of marks by a playful giant child, as though the whole rock bore a
wondrous decoration of chains, rings, and stars. From the dark
depths of large and small cavities there gleamed a brilliant white; the
shelving ledges stood out in more conspicuous brightness. The
brooding gulls on their nests formed the white pattern, and we
realized the truth of Faber’s words, “they cover the rocks when they
sit”.
Fig. 4.—Razor-bills.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com