Kubernetes Quick Start

Course

January 28th, 2019

Intro Video

Photo of Michael McClaren

Michael McClaren

Linux Training Architect I in Content

Length

02:41:26

Difficulty

Beginner

Course Details

This course will serve as an introduction to Kubernetes and will cover the basic installation and configuration needed to get a Kubernetes cluster up and running. We will also discuss deployments and pod versioning. In the end there will be a hands on activity that allows you to take what you have learned and put it to use to set up a Kuberenetes cluster for your self.

Download the Interactive Diagram here: https://interactive.linuxacademy.com/diagrams/KubernetesQuickStart.html

Syllabus

Basics and Installation

Getting Started

What Is Kubernetes, and Why Do I Need It?

00:07:00

Lesson Description:

In this lesson, we will take a look at the limitations of basic Docker and how Kubernetes can help overcome those limitations. We will also take a look at the simplified architecture of a Kubernetes cluster and get a sneak peek at what we will be building as the course progresses.

Installing Kubernetes

00:11:42

Lesson Description:

This lesson covers how to install Kubernetes on a CentOS 7 server in our Cloud Playground. Below, you will find a list of the commands used in this lesson. *Note in this lesson we are using 3 unit servers as this meets the minimum requirements for the Kubernetes installation. Use of a smaller size server (less than 2 cpus) will result in errors during installation. The first thing that we are going to do is use SSH to log in to all machines. Once we have logged in, we need to elevate privileges using sudo. sudo su Disable SELinux. setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinuxEnable the br_netfilter module for cluster communication. modprobe br_netfilter echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptablesDisable swap to prevent memory allocation issues. swapoff -a vim /etc/fstab.orig -> Comment out the swap lineInstall the Docker prerequisites. yum install -y yum-utils device-mapper-persistent-data lvm2Add the Docker repo and install Docker. yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install -y docker-ceConigure the Docker Cgroup Driver to systemd, enable and start Docker sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service systemctl daemon-reload systemctl enable docker --nowAdd the Kubernetes repo. cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg EOFInstall Kubernetes. yum install -y kubelet kubeadm kubectlEnable Kubernetes. The kubelet service will not start until you run kubeadm init. systemctl enable kubelet *Note: Complete the following section on the MASTER ONLY! Initialize the cluster using the IP range for Flannel. kubeadm init --pod-network-cidr=10.244.0.0/16Copy the kubeadmin join command. Exit sudo and run the following: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/configDeploy Flannel. kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlCheck the cluster state. kubectl get pods --all-namespaces *Note: Complete the following steps on the NODES ONLY! Run the join command that you copied earlier (this command needs to be run as sudo), then check your nodes from the master.kubectl get nodes

Masters and Nodes

00:05:27

Lesson Description:

In this lesson, we will take a quick look at what was installed when we ran the kubeadm command. We will see that the nodes are fairly lightweight and that most of the pods that get deployed during a Kubernetes installation are on the master node.

Containers, Orchestration, and Clusters

Orchestration

Pods and Containers

00:10:08

Lesson Description:

In this lesson, we will explore pods, look at a Pod declaration file, and see how to declare and mount shared volumes. We will also see an example of how the containers share the IP space of the Pod and how we can go from the host node to the IP address of the Pod to see the output of the Pod's nginx instance. The pod-example.yaml file apiVersion: v1 kind: Pod metadata: name: examplepod namespace: pod-example spec: volumes: - name: html emptyDir: {} containers: - name: webcontainer image: nginx volumeMounts: - name: html mountPath: /usr/share/nginx/html - name: filecontainer image: debian volumeMounts: - name: html mountPath: /html command: ["/bin/sh", "-c"] args: - while true; do date >> /html/index.html; sleep 1; done

Networking

00:07:30

Lesson Description:

In this lesson, we are going to take a quick look at the network overlay. In this case, we are looking at flannel. This is not an in-depth look at Kubernetes networking. Rather, the goal here is to understand how flannel configures the network and why this network is necessary in the scope of Kubernetes. Hopefully this lesson will help you understand a bit about networking in Kubernetes.

DNS

00:04:28

Lesson Description:

In this lesson, we will take a very brief look at DNS in the cluster, as well as A records and namespaces. This will set us up for a look at services later in the course.

ReplicaSets

00:06:34

Lesson Description:

In this lesson, we will take a look at ReplicaSets. We will look at the file structure of the YAML file that is used to create the ReplicaSet, as well as how to scale and delete ReplicaSets. Contents of replicas-example.yaml: apiVersion: apps/v1 kind: ReplicaSet metadata: name: frontend labels: app: nginx tier: frontend spec: replicas: 2 selector: matchLabels: tier: frontend matchExpressions: - {key: tier, operator: In, values: [frontend]} template: metadata: labels: app: nginx tier: frontend spec: containers: - name: nginx image: darealmc/nginx-k8s:v1 ports: - containerPort: 80

Services

00:10:12

Lesson Description:

In this lesson, we will look at services in Kubernetes and how they allow us to provide high availability. We will see how labels are used to connect pods to services, and we will take a peek into DNS to see how using a service allows us to resolve a name to access groups of pods. service-example.yaml: kind: Service apiVersion: v1 metadata: name: my-awesome-service spec: selector: app: nginx ports: - protocol: TCP port: 32768 targetPort: 80

Deployments

00:08:21

Lesson Description:

In this lesson, we will look at creating a Deployment. We will see how we can use Deployments to manage ReplicaSets. We will look at versioning our Deployments and how a Deployment will gracefully roll out those new versions. deployexample.yaml: apiVersion: apps/v1 kind: Deployment metadata: name: example-deployment labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: darealmc/nginx-k8s:v1 ports: - containerPort: 80

Hands-on Labs are real live environments that put you in a real scenario to practice what you have learned without any other extra charge or account to manage.

01:30:00