• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    HTML
  • Created over 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Training Guide

Kubernetes Options

Rancher gives you several options for running Kubernetes. You can use these or any other CNCF-certified Kubernetes distribution.

  • K3s - Lightweight Kubernetes that works both in the datacenter and resource-constrained environments like IoT and the Edge.
  • RKE - A complete installation of Kuberntets that runs inside of Docker containers.
  • RKE2 - The next generation of RKE, using ContainerD and FIPS compliant.
  • K3d - Runs a multi-node Kubernetes cluster within Docker. Designed for local development operations.

Deploy K3s

Local Deployment

For this you'll need to be logged into a Linux system.

curl -sfL https://get.k3s.io | sh -

Remote Deployment over SSH

For this you'll need a Linux system you can SSH into. We'll use the k3sup command available from k3sup.dev. The defaults assume that you're using ~/.ssh/id_rsa as your key and connecting as the root user. If you need to change these or other defaults, see the output from k3sup install --help.

All k3sup needs to install K3s over SSH is the IP of the destination server. We're adding a release channel to make sure that we're running the stable release, and not the latest.

# replace this with the IP of your host

# Bash
export IP=10.68.0.143

# Fish
set -x IP 10.68.0.143

k3sup install --ip=$IP --k3s-channel=stable

Alternatively, to install a specific version:

export VERSION=v1.19.4+k3s1
k3sup install --ip=$IP --k3s-version=$VERSION

You can add additional configuration. See k3sup --help and k3s help server, as well as the Rancher Documentation

k3sup install --ip=$IP --k3s-version=$VERSION --local-path=config.a.yaml --context a

Working With Kubernetes

Using kubectl

If you're using a local installation of K3s, the kubectl binary already points to the configuration file, located at /etc/rancher/k3s/k3s.yaml.

If you're using a remote system installed via k3sup, the config was locally saved in the current working directory. Point the KUBECONFIG environment variable at it.

# Bash
export KUBECONFIG=$(pwd)/kubeconfig

# Fish
set -x KUBECONFIG (pwd)/kubeconfig

Verify your installation and that you're pointed to the right cluster.

kubectl get nodes

kubectl supports plugins that can help make things easier. I'll be using kubectl neat when showing manifests. You can install plugins with krew.

You'll also want to start using aliases. See this repository for a system of aliases that will make your life easier.

Kui is a wonderful utility for interacting with Kubernetes that gives you rich information for exploring the cluster and its workloads.

Kubie is a utility for switching between Kubernetes clusters and contexts (namespaces) with isolation between terminal windows. It works great with Kui to keep it pointed at the right cluster.

kubie ctx a  # will search KUBECONFIG for the a context
kubie ctx -f config.a.yaml  # will use the contents of this config
kubie ns training # will switch to the "training" namespace

I have these aliased:

alias kcc="kubie ctx"
alias ns="kubie ns"

Pods

Smallest unit you can deploy in Kubernetes. The actual workload.

kubectl apply -f 01-pod/pod.yaml
kubectl logs myapp-pod
kubectl get po -w
kubectl delete po myapp-pod

Watch how Kubernetes tries to restart the Pod and then backs off the restart timer.

kubectl get po -w

Deployment

Creates a ReplicaSet that in turn creates and manages one or more Pods

kubectl create deploy nginx --image=nginx:1.19-alpine
kubectl get deploy
kubectl get replicaset
kubectl get po

Describe the pod, look at the image

kubectl describe po/<pod name>
kubectl get po/<pod name> -o yaml | less

Scale the Deployment manually

kubectl scale deploy/nginx --replicas=3
kubectl rollout status deploy/nginx
kubectl get deploy
kubectl get po

What happens if we upgrade with a bad image?

kubectl set image deploy/nginx nginx=nginx:1.20-alpne
kubectl rollout status deploy/nginx
kubectl get po
kubectl rollout undo deploy/nginx

We can redo the upgrade from the manifest.

kubectl edit deploy/nginx

ConfigMaps

ConfigMaps allow us to override data within the container.

kubectl exec -it <pod-name> -- ash
cat /usr/share/html/index.html

We can see that the HTML file is the default. We can override this directory with a ConfigMap

cd 02-deployment/base
cat configs/index.html
cat deployment.yaml  # how is the ConfigMap created?

A tool called Kustomize, built into kubectl can assemble all of this from templates.

cat kustomize.yaml
kustomize build . | less

We can see the ConfigMap was generated with a unique name. This forces a rolling update when the ConfigMap changes, which keeps us in line with GitOps and the repository being the source of truth.

Kustomize allows us to create and template content, reducing human error present when copying things between manifests.

We'll use this in a later section.

Services

Let's deploy something that will show us interesting traffic.

cd 03-rancher-demo
cat kustomization.yaml
kubectl apply -k .

# Bash
export PORT=$(kubectl get service/demo -o jsonpath='{.spec.ports[0].nodePort}')

# Fish
set -x PORT (kubectl get service/demo -o jsonpath='{.spec.ports[0].nodePort}')

# Use $IP from the top of this README
curl -I $IP:$PORT

# Open $IP:$PORT in a browser

We can demonstrate the benefits of Kustomize and a ConfigMap by editing kustomization.yaml and changing the value of COW_COLOR.

vi kustomization.yaml
# change COW_COLOR to pink and save

kubectl apply -k .
kubectl get po -w

If we look at the Deployment YAML now, we'll see that the configMapRef was updated to use the new ConfigMap that Kustomize created. This gives us a clear path for rolling back if we want. If we had updated in place, the Deployment wouldn't have changed, and we wouldn't be able to roll back the change to the configuration.

kubectl rollout undo deploy demo

The cows are yellow again.

Ingress

# still in 03-rancher-demo
kubectl apply -f ingress.yaml
kubectl get ingress
curl -I -H 'Host: rancher-demo.home.monach.us' http://$IP/

Cleanup

Delete it all.


Rancher

Server Deploy

helm repo add jetstack https://charts.jetstack.io
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm repo update

helm install cert-manager jetstack/cert-manager --namespace cert-manager --set installCRDs=true --create-namespace

kubectl get po -n cert-manager -w

# Bash
export HOSTNAME=rancher-training.home.monach.us

# Fish
set -x $HOSTNAME rancher-training.home.monach.us

helm install rancher rancher-stable/rancher --namespace cattle-system --set hostname=$HOSTNAME --create-namespace

Walkthrough

  • Cluster Explorer
  • Apps
  • Continuous Delivery

Remember Kustomize? We'll use it now.

  • Show the kustomization files and how they work together
  • Deploy with Fleet: https://github.com/rancher/k8s-intro-training with the 02-deployment folder

More Repositories

1

rancher

Complete container management platform
Go
23,193
star
2

os

Tiny Linux distro that runs the entire OS as Docker containers
Go
6,437
star
3

k3os

Purpose-built OS for Kubernetes, fully managed by Kubernetes.
Go
3,403
star
4

rke

Rancher Kubernetes Engine (RKE), an extremely simple, lightning fast Kubernetes distribution that runs entirely within containers.
Go
3,197
star
5

rio

Application Deployment Engine for Kubernetes
Go
2,282
star
6

local-path-provisioner

Dynamically provisioning persistent local storage with Kubernetes
Go
2,138
star
7

fleet

Deploy workloads from Git to large fleets of Kubernetes clusters
Go
1,514
star
8

convoy

A Docker volume plugin, managing persistent container volumes.
Go
1,308
star
9

rke2

Go
1,028
star
10

old-vm

(OBSOLETE) Package and Run Virtual Machines as Docker Containers
Go
646
star
11

ui

Rancher UI
JavaScript
598
star
12

cattle

Infrastructure orchestration engine for Rancher 1.x
Java
574
star
13

k3c

Lightweight local container engine for container development
Go
571
star
14

system-upgrade-controller

In your Kubernetes, upgrading your nodes
Go
502
star
15

dashboard

The Rancher UI
Vue
449
star
16

charts

Github based Helm Chart Index Repository providing charts crafted for Rancher Manager
Smarty
389
star
17

community-catalog

Catalog entries contributed by the community
Smarty
384
star
18

install-docker

Scripts for docker-machine to install a particular docker version
Shell
370
star
19

dapper

Docker build wrapper
Go
358
star
20

quickstart

HCL
357
star
21

terraform-provider-rke

Terraform provider plugin for deploy kubernetes cluster by RKE(Rancher Kubernetes Engine)
Go
340
star
22

opni

Multi Cluster Observability with AIOps
Go
334
star
23

cli

Rancher CLI
Go
331
star
24

kim

In ur kubernetes, buildin ur imagez
Go
326
star
25

trash

Minimalistic Go vendored code manager
Go
296
star
26

elemental

Elemental is an immutable Linux distribution built to run Rancher and its corresponding Kubernetes distributions RKE2 and k3s. It is built using the Elemental-toolkit
Go
295
star
27

terraform-controller

Use K8s to Run Terraform
Go
292
star
28

elemental-toolkit

❄️ The toolkit to build, ship and maintain cloud-init driven Linux derivatives based on container images
Go
272
star
29

remotedialer

HTTP in TCP in Websockets in HTTP in TCP, Tunnel all the things!
Go
255
star
30

terraform-provider-rancher2

Terraform Rancher2 provider
Go
222
star
31

rancher-compose

Docker compose compatible client to deploy to Rancher
Go
214
star
32

wrangler

Write controllers like a boss
Go
205
star
33

os-vagrant

Ruby
176
star
34

k3k

Kubernetes in Kubernetes
Go
163
star
35

rancher-cleanup

Shell
160
star
36

rancher-catalog

Smarty
155
star
37

docs

Documentation for Rancher products (for 2.0/new site)
SCSS
140
star
38

fleet-examples

Fleet usage examples
Shell
140
star
39

catalog-dockerfiles

Dockerfiles for Rancher Catalog containers
Shell
131
star
40

api-spec

Specification for Rancher REST API implementation
121
star
41

ansible-playbooks

Rancher 1.6 Installation. Doesn't support Rancher 2.0
Python
113
star
42

sherdock

Docker Image Manager
JavaScript
110
star
43

norman

APIs on APIs on APIs
Go
108
star
44

docker-from-scratch

Tiny Docker in Docker
Go
105
star
45

backup-restore-operator

Go
99
star
46

lb-controller

Load Balancer for Rancher services via ingress controllers backed up by a Load Balancer provider of choice
Go
97
star
47

pipeline

Go
96
star
48

container-crontab

Simple cron runner for containers
Go
88
star
49

terraform-modules

Rancher Terraform Modules
HCL
85
star
50

system-charts

Replaced by rancher/charts. The deprecation process is in progress.
Mustache
84
star
51

os2

EXPERIMENTAL: A Rancher and Kubernetes optimized immutable Linux distribution based on openSUSE
Go
82
star
52

cluster-api-provider-rke2

RKE2 bootstrap and control-plane Cluster API providers.
Go
81
star
53

vagrant

Vagrant file to stand up a Local Rancher install with 3 nodes
Shell
79
star
54

rancher-dns

A simple DNS server that returns different answers depending on the IP address of the client making the request
Go
79
star
55

giddyup

Go
78
star
56

kontainer-engine

Provisioning kubernetes cluster at ease
Go
78
star
57

go-rancher

Go language bindings for Rancher API
Go
74
star
58

go-skel

Skeleton for Rancher Go Microservices
Shell
71
star
59

runc-cve

CVE patches for legacy runc packaged with Docker
Dockerfile
69
star
60

terraform-k3s-aws-cluster

HCL
67
star
61

agent

Shell
64
star
62

kontainer-driver-metadata

This repository is to keep information of k8s versions and their dependencies like k8s components flags and system addons images.
Go
63
star
63

external-dns

Service updating external DNS with Rancher services records for Rancher 1.6
Go
63
star
64

terraform-provider-rancher2-archive

[Deprecated] Use https://github.com/terraform-providers/terraform-provider-rancher2
Go
62
star
65

gitjob

Go
59
star
66

types

Rancher API types
Go
59
star
67

rancher-docs

Rancher Documentation
JavaScript
58
star
68

rancher.github.io

HTML
58
star
69

ui-driver-skel

Skeleton Rancher UI driver for custom docker-machine drivers
JavaScript
58
star
70

rke2-charts

Shell
56
star
71

os-services

RancherOS Service Compose Templates
Shell
54
star
72

turtles

Rancher CAPI extension
Go
50
star
73

client-python

A Python client for Rancher APIs
Python
49
star
74

hyperkube

Rancher hyperkube images
48
star
75

partner-charts

A catalog based on applications from independent software vendors (ISVs). Most of them are SUSE Partners.
Smarty
47
star
76

rancher-cloud-controller-manager

A kubernetes cloud-controller-manager for the rancher cloud
Go
44
star
77

steve

Kubernetes API Translator
Go
43
star
78

rodeo

Smarty
43
star
79

cluster-template-examples

43
star
80

cis-operator

Go
43
star
81

rancherd

Bootstrap Rancher and k3s/rke2
Go
42
star
82

10acre-ranch

Build Rancher environment on GCE
Shell
41
star
83

elemental-operator

The Elemental operator is responsible for managing the OS versions and maintaining a machine inventory to assist with edge or baremetal installations.
Go
41
star
84

secrets-bridge

Go
40
star
85

storage

Rancher specific storage plugins
Shell
39
star
86

k8s-sql

Storage backend for Kubernetes using Go database/sql
Go
37
star
87

lasso

Low level generic controller framework
Go
36
star
88

server-chart

[Deprecated] Helm chart for Rancher server
Shell
36
star
89

os-packer

Shell
36
star
90

pipeline-example-go

Go
36
star
91

system-tools

This repo is for tools helping with various cleanup tasks for rancher projects. Example: rancher installation cleanup
Go
35
star
92

rancher-metadata

A simple HTTP server that returns EC2-style metadata information that varies depending on the source IP address making the request.
Go
31
star
93

os-base

Base file system for RancherOS images
Shell
31
star
94

image-mirror

Shell
31
star
95

websocket-proxy

Go
29
star
96

rke-tools

Tools container for supporting functions in RKE
Go
29
star
97

gdapi-python

Python Binding to API spec
Python
28
star
98

wins

Windows containers connect to Windows host
Go
28
star
99

api-ui

Embedded UI for any service that implements the Rancher API spec
JavaScript
27
star
100

migration-tools

Go
27
star