Difference between revisions of "IT-SDK-Kubernetes-Basics"

From wiki.samerhijazi.net
Jump to navigation Jump to search
(Installation)
(Fast-Run)
Line 65: Line 65:
 
</pre>
 
</pre>
  
 +
=Settings=
 +
<pre class="code">
 +
kubectl describe node | grep -i taint
 +
kubectl taint nodes --all node-role.kubernetes.io/master-
 +
</pre>
 
=Fast-Run=
 
=Fast-Run=
 
<pre class="code">
 
<pre class="code">

Revision as of 23:16, 21 July 2021

Ref.

Infrastructure

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
    config.vm.provider "virtualbox" do |vb|
        vb.gui = false
        vb.cpus = 2
        vb.memory = 4096
    end      
    config.vm.define "k8s-master" do |master|
        master.vm.box = "ubuntu/focal64"
        master.vm.hostname = "k8s-master"
        master.vm.network "public_network", bridge: "br0", mac: "0800272657FA"
    end    
    config.vm.define "k8s-node01" do |node01|
        node01.vm.box = "ubuntu/focal64"
        node01.vm.hostname = "k8s-node01"            
        node01.vm.network "public_network", bridge: "br0",  mac: "080027B6FE37"
    end    	
end

Installation

swapoff -a
sudo apt-get update
sudo apt-get upgrade 
sudo apt-get install docker.io
...
sudo sh -c "echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' >> /etc/apt/sources.list.d/kubernetes.list"
sudo sh -c "curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -"
...
sudo apt-get update
sudo apt-get install kubeadm=1.20.1-00 kubelet=1.20.1-00 kubectl=1.20.1-00
sudo apt-mark hold kubelet kubeadm kubectl
...
sudo sh -c "echo '192.168.178.82 k8scp' >> /etc/hosts"
nano kubeadm-config.yaml
---------------------------
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: 1.20.1
controlPlaneEndpoint: "k8scp:6443"
networking:
  podSubnet: 192.168.0.0/16
---------------------------
sudo kubeadm init --config=kubeadm-config.yaml --upload-certs | tee kubeadm-init.out
sudo kubeadm init --kubernetes-version 1.20.1 --pod-network-cidr 192.168.0.0/16 # Alternativ
...
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
...
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
kubectl get node
kubectl config use-context kubernetes-admin@kubernetes

Settings

kubectl describe node | grep -i taint
kubectl taint nodes --all node-role.kubernetes.io/master-

Fast-Run

kubectl run  --image=nginx -o yaml --dry-run=client > pod-defination.yaml
kubectl create deployment --image=nginx --replicas=3 -o yaml --dry-run=client > deployment-defination.yaml

ServiceTypes

Probes

Bedeutung

  • Probe: describes a health check to be performed against a container to determine whether it is alive or ready to receive traffic.
  • Liveness: to know when to restart a container.
  • Readiness: to know when a container is ready to start accepting traffic.
  • Startup: to know when a container application has started. If such a probe is configured, it disables liveness and readiness checks until it succeeds.

Settings

  • initialDelaySeconds: wait x seconds before performing the first probe.
  • periodSeconds: every x seconds to perform probe.
  • timeoutSeconds: wait x seconds after which the probe times out.
  • successThreshold: x times to considered successful after having failed (Defaults=1).
  • failureThreshold: x times to giving up after fails (Defaults=3). Giving up in case of liveness probe means restarting the container.

kind

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
curl -Lo kind.exe https://kind.sigs.k8s.io/dl/v0.11.1/kind-windows-amd64
kind create cluster
kind create cluster --name kind-2
kind get clusters
kind delete cluster
...
kubectl cluster-info --context kind-kind

minikube

minikube start
minikube dashboard
minikube stop		            #Halt the cluster:
minikube config set memory 16384    #Set memory limit
minikube addons list	            #Browse the catalog
minikube start -p aged --kubernetes-version=v1.16.1		#Create a second cluster
minikube delete --all		    #Delete all of the minikube