Getting Started With Kubernetes PDF
Getting Started With Kubernetes PDF
com
About Opensource.com
What is Opensource.com?
Scott McCarty
Twitter: https://twitter.com/fatherlinux
Introduction
Chapters
Write for Us 15
Kubernetes is a dump
truck: Here’s why
Dump trucks are an elegant solution to a wide range of essential business problems.
The short answer, in either case, is you have to move into So yes, there is a learning curve when starting to use a
container orchestration. giant dump truck (or any professional equipment). There’s
Inevitably, when you start to handle the two containers or also a learning curve to use Kubernetes, but it’s worth it be-
two hosts problem, you’ll introduce complexity and, hence, cause you can solve so many problems with one tool. If you
a learning curve. The two services (a more generalized ver- are apprehensive about the learning curve, think through all
sion of a container) / two hosts problem has been around the underlying networking, storage, and security problems in
for a long time and has always introduced complexity. IT infrastructure and envision their solutions today—they’re
Historically, this would have involved load balancers, clus- not easier. Especially when you introduce more and more
tering software, and even clustered file systems. Configu- services, faster and faster. Velocity is the goal nowadays, so
ration logic for every service is embedded in every system give special consideration to the provisioning and de-provi-
(load balancers, cluster software, and file systems). Running sioning problem.
60 or 70 services, clustered, behind load balancers is com- But don’t confuse the learning curve for building or equip-
plex. Adding another new service is also complex. Worse, ping Kubernetes (picking the right mud flaps for your dump
decommissioning a service is a nightmare. Thinking back on truck can be hard, LOL) with the learning curve for using it.
my days of troubleshooting production MySQL and Apache Learning to build your own Kubernetes with so many differ-
servers with logic embedded in three, four, or five different ent choices at so many different layers (container engine,
places, all in different formats, still makes my head hurt. logging, monitoring, service mesh, storage, networking),
Kubernetes elegantly solves all these problems with one and then maintaining updated selections of each component
piece of software: every six months, might not be worth the investment—but
1. Two services (containers): Check learning to use it is absolutely worth it.
2. Two servers (high availability): Check I eat, sleep, and breathe Kubernetes and containers ev-
3. Single source of configuration: Check ery day, and even I struggle to keep track of all the ma-
4. Standard configuration format: Check jor new projects announced literally almost every day. But
5. Networking: Check there isn’t a day that I’m not excited about the operational
6. Storage: Check benefits of having a single tool to model an entire IT mini-
7. Dependencies (what services talk to what databases): verse. Also, remember Kubernetes has matured a ton and
Check will continue to do so. Like Linux and OpenStack before it,
8. Easy provisioning: Check the interfaces and de facto projects at each layer will ma-
9. Easy de-provisioning: Check (perhaps Kubernetes’ ture and become easier to select.
most powerful piece)
Wait, it’s starting to look like Kubernetes is pretty elegant and
pretty powerful. It is. You can model an entire miniature IT Links
universe in Kubernetes. [1] https://kubernetes.io/
Kubernetes basics:
Learn how to drive first
Quit focusing on new projects and get focused on getting your
Kubernetes dump truck commercial driver's license.
Primitives
Next, you need to understand what primitives you can specify
in Kubernetes. Defined state and actual state
veloper-native way, until Kubernetes. If you think about it, and compute resources in a very portable and declara-
we are extending the ability to manage storage, network, tive way with the YAML/JSON files we write in Kuberne-
tes, but they are always
mapped back to “real”
resources somewhere.
We just don’t have to
worry about it in devel-
oper mode.
So, quit focusing on
new projects in the Ku-
bernetes ecosystem and
get focused on driving it.
Links
[1] https://www.reddit.
com/r/kubernetes/
comments/
bsoixc/what_are_
the_essential_
kubernetes_related/
[2] https://www.openshift.
com/
Kubernetes primitives
1. Katacoda
Katacoda [1] is the easiest way to
test-drive a Kubernetes cluster,
hands-down. With one click and
five seconds of time, you have
a web-based terminal plumbed
straight into a running Kuberne-
tes cluster. It’s magnificent for
playing and learning. I even use
it for demos and testing out new
ideas. Katacoda provides a com-
pletely ephemeral environment
that is recycled when you finish
using it. OpenShift Playground [2]
you. Brent Baude [9] is even working on new features when developing primitives to describe your own applica-
like adding Volumes/Persistent Volume Claims [10]. For tions. After you run the above command, your Kubernetes
a deeper dive, check out Brent’s amazing work in his blog namespace (in OpenShift) will be populated by a bunch of
post “Podman can now ease the transition to Kubernetes new, defined resources.
and CRI-O.” [11]
oc get all
3. oc new-app
The oc new-app command is extremely powerful. It’s Open- See the “occ new-app output”:
Shift-specific, so it’s not available in default Kubernetes, but The beauty of this is that you can delete Pods, watch
it’s really useful when you’re starting to learn Kubernetes. the replication controllers recreate them, scale Pods up,
Let’s start with a quick command to create a fairly sophisti- and scale them down. You can play with the template and
cated application: change it for other applications (which is what I did when I
first started).
oc new-project -n example
oc
new-app -f https://raw.githubusercontent.com/openshift/ 4. Visual Studio Code
origin/master/examples/quickstarts/cakephp-mysql.json I saved one of my favorites for last. I use vi [12] for most of
my work, but I have never found a good syntax highlight-
With oc new-app, you can literally steal templates from the er and code completion plugin for Kubernetes (if you have
OpenShift developers and have a known, good starting point one, let me know). Instead, I have found that Microsoft’s
NAME HOST/PORT
PATH SERVICES PORT TERMINATION WILDCARD
ute.route.openshift.io/cakephp-mysql-example
ro cakephp-mysql-example-example.2886795271-80-rhsummit1.environments.katacoda.com
cakephp-mysql-example <all> None
VS Code [13] has a killer set of plugins that complete the ments, etc. This is a really nice feature when you are build-
creation of Kubernetes resources and provide boilerplate. ing these files from scratch or even modifying the files you
First, install Kubernetes and YAML plugins shown in the create with Podman generate kube.
“VS Code plugins UI” image.
Then, you can create a new YAML file from scratch and Conclusion
get auto-completion of Kubernetes resources. The example These four tools (six if you count the two plugins) will help
“Autocomplete in VS Code” shows a Service. you learn to drive Kubernetes, instead of building or equip-
When you use autocomplete and select the Service re- ping it.
source, it fills in some boilerplate for the object. This is mag-
nificent when you are first learning to drive Kubernetes. You Links
can build Pods, Services, Replication Controllers, Deploy- [1] https://learn.openshift.com/subsystems/container-
internals-lab-2-0-part-1
[2] https://learn.openshift.com/playgrounds/openshift311/
[3] https://katacoda.com/courses/kubernetes/playground
[4] https://learn.openshift.com/subsystems/container-
internals-lab-2-0-part-1
[5] https://katacoda.com/learn
[6] http://learn.openshift.com/
[7] https://podman.io/
[8] https://learn.openshift.com/subsystems/container-
internals-lab-2-0-part-1
[9] https://developers.redhat.com/blog/author/bbaude/
[10] https://github.com/containers/libpod/issues/2303
[11] https://developers.redhat.com/blog/2019/01/29/podman-
kubernetes-yaml/
[12] https://en.wikipedia.org/wiki/Vi
[13] https://code.visualstudio.com/
VS Code plugins UI
Write for Us
In 2010, Red Hat CEO Jim Whitehurst announced the launch of Opensource.com
in a post titled Welcome to the conversation on Opensource.com. He explained,
“This site is one of the ways in which Red Hat gives something back to the open
source community. Our desire is to create a connection point for conversations
about the broader impact that open source can have—and is having—even beyond
the software world.” he wrote, adding, “All ideas are welcome, and all participants
are welcome. This will not be a site for Red Hat, about Red Hat. Instead, this will be
a site for open source, about the future.”
More than 60% of our content is contributed by members of open source communities,
and additional articles are written by the editorial team and other Red Hat contributors.
A small, international team of staff editors and Community Moderators work closely
with contributors to curate, polish, publish, and promote open source stories from
around the world.
Would you like to write for us? Send pitches and inquiries to [email protected].