Learning how to ride Kubernetes is more important than learning how to build it, and these tools can help you get on the road faster.

Tools in a workshop

In the third article in this series, Kubernetes Basics: First learn how to use It, I emphasized that you should learn to use Kubernetes, not build it. I also explained that in Kubernetes, you have to learn a minimal set of primitives to model your application. I want to emphasize this point: the set of primitives you need to learn is the simplest set of primitives from which you can learn how to implement production-level application deployment (i.e., high availability [HA], multi-container, multi-application). In other words, IT’s easier to learn the built-in Kubernetes primitive set than IT is to learn clustering software, clustered file systems, load balancers, crazy Configurations of Apache and Nginx, routers, switches, firewalls, and storage backends — all of which you can model simple HA in a traditional IT environment (virtual machine or bare metal) What the application needs.

In this fourth article, I’ll share some tools that will help you learn to ride Kubernetes quickly.

1, Katacoda

Katacoda is undoubtedly the easiest way to test drive a Kubernetes cluster. With one click, you can connect a Web-based terminal directly to a running Kubernetes cluster five seconds later. This is great for use and learning. I’ve even used it to demonstrate and test new ideas. Katacoda provides a complete temporary environment that can be recycled after you’ve used it.

OpenShift Playground

OpenShift Playground

Kubernetes Playground

Kubernetes Playground

Katacoda provides a temporary environment and a more in-depth laboratory environment. For example, the Linux Container Internals Lab THAT I’ve been teaching for the last three or four years was built in Katacoda.

Katacoda maintains several Kubernetes and cloud tutorials on its main site and works with Red Hat to support a dedicated Learning portal for OpenShift. Check them out. They’re great learning resources.

When you first learn to drive a dump truck, it’s a good idea to observe how other people drive.

Podman generate kube

The Podman Generate Kube command is a great subcommand to help users naturally transition from a simple container engine running a simple container to a cluster use case running many containers (as I described in the previous article). Podman does this by having you start a new container, then export the working Kube YAML, and start it in Kubernetes. Check this out (you can run it in Katacoda Lab, which already has Podman and OpenShift).

First, note that the syntax for running containers is very similar to Docker:

podman run -dtn two-pizza quay.io/fatherlinux/two-pizza
Copy the code

But this is something that other container engines don’t have:

podman generate kube two-pizza
Copy the code

Output:

# Generation of Kubernetes YAML is still under development!
#
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman - 1.3.1
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2019-06-07T08:08:12Z"
  labels:
    app: two-pizza
  name: two-pizza
spec:
  containers:
  - command:
    - /bin/sh
    - -c
    - bash -c 'while true; do /usr/bin/nc -l -p 3306 < /srv/hello.txt; done'
    env:
    - name: PATH
      value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    - name: TERM
      value: xterm
    - name: HOSTNAME
    - name: container
      value: oci
    image: quay.io/fatherlinux/two-pizza:latest
    name: two-pizza
    resources: {}
    securityContext:
      allowPrivilegeEscalation: true
      capabilities: {}
      privileged: false
      readOnlyRootFilesystem: false
    tty: true
    workingDir: /
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2019-06-07T08:08:12Z"
  labels:
    app: two-pizza
  name: two-pizza
spec:
  selector:
    app: two-pizza
  type: NodePort
status:
  loadBalancer: {}
Copy the code

You now have some work to do with Kubernetes YAML, which you can use as a starting point for practice to learn, adjust, etc. The -S logo creates a service for you. Brent Baude even worked on new features such as volume/persistent volume assertions. If you want to dig deeper, check out Brent’s work in his blog post “Podman Can Now easily transition to Kubernetes and Cri-O.”

3, oc new app

The oc new-app command is very powerful. It’s OpenShift-specific, so it’s not available in the default Kubernetes, but it’s very useful when you start learning Kubernetes. Let’s start with a quick command to create a fairly complex application:

oc new-project -n example
oc new-app -f https://raw.githubusercontent.com/openshift/origin/master/examples/quickstarts/cakephp-mysql.json
Copy the code

With OC New-app, you can steal templates from OpenShift developers and have a known good starting point when developing primitives to describe your own applications. After running the above command, your Kubernetes namespace (in OpenShift) will be populated with several new defined resources.

oc get all
Copy the code

Output:

NAME READY STATUS RESTARTS AGE pod/cakephp-mysql-example-1-build 0/1 Completed 0 4m pod/cakephp-mysql-example-1-gz65l 1/1 Running 0 1m pod/mysql-1-nkhqn 1/1 Running 0 4m NAME DESIRED CURRENT READY AGE replicationcontroller/cakephp-mysql-example-1 1 1 1 1m replicationcontroller/mysql-1 1 1 1 4m NAME TYPE CLUSTER-IP External-ip PORT(S) AGE service/cakephp-mysql-example ClusterIP 172.30.234.135 <none> 8080/TCP 4M service/mysql ClusterIP 172.30.13.195 < None > 3306/TCP 4M NAME REVISION DESIRED CURRENT TRIGGERED BY deploymentconfig.apps.openshift.io/cakephp-mysql-example 1 1 1 config,image(cakephp-mysql-example:latest) Deploymentconfig. Apps. Openshift. IO/mysql 1 1 1 config, image (mysql: 5.7) NAME the TYPE FROM the LATEST buildconfig.build.openshift.io/cakephp-mysql-example Source Git 1 NAME TYPE FROM STATUS STARTED DURATION build.build.openshift.io/cakephp-mysql-example-1 Source Git@47a951e Complete 4 minutes ago 2m27s NAME DOCKER REPO TAGS UPDATED imagestream.image.openshift.io/cakephp-mysql-example docker-registry.default.svc:5000/example/cakephp-mysql-example latest About aminute ago NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD route.route.openshift.io/cakephp-mysql-example cakephp-mysql-example-example.2886795271-80-rhsummit1.environments.katacoda.com cakephp-mysql-example <all> NoneCopy the code

The advantage of this is that you can remove the pods, watch how the copy controller recreates them, scale the pods, and so on. You can take the template and change it to another application (this is what I did when I first started).

4. Visual Studio Code

I saved my favorite for last. I use VI for most of my work, but I’ve never found a good syntax highlighting and code completion plug-in for Kubernetes (let me know if there is one). Instead, I found that Microsoft’s VS Code has a killer set of plug-ins that complete the creation of Kubernetes resources and provide templates.

VS Code plugins UI

First, install the Kubernetes and YAML plug-ins shown in the image above.

Autocomplete in VS Code

You can then create a new YAML file from scratch and automatically complete Kubernetes resources. The example above shows a service.

VS Code autocomplete filling in boilerplate for an object

When you use autocomplete and select a service resource, it populates some templates for that object. This is great when you first learn to use Kubernetes. You can build pods, services, replication controllers, deployments, and more. This is a great feature when you build these files from scratch and even modify the files you created with Podman Generate Kube.

conclusion

These four tools (six if you count two plug-ins) will help you learn to ride Kubernetes, rather than build or equip it. In the final article in this series, I’ll discuss why Kubernetes is so good for running so many different workloads.


Via: opensource.com/article/19/…

By Scott McCarty, lujun9972

This article is originally compiled by LCTT and released in Linux China