Benutzer-Werkzeuge

Webseiten-Werkzeuge


kubernetes

improve

Kubernetes ist ein OpenSource System zur Automatisierung der Bereitstellung, Skalierung und Verwaltung von Container-Anwendungen (siehe Docker), das ursprünglich von Google entworfen wurde. Docker hat ein integriertes Tool (Docker Swarm) zum selben Zweck, Kubernetes kann jedoch das selbe und noch viel mehr und wird ab Werk von Docker unterstützt.

Kubernetes ist deklarativ, das bedeutet man beschreibt den gewünschten Endzustand.

Ein Pod ist eine Resource eines Replicaset was eine Resourse eines Deployment ist.

Installation (Ubuntu)

At least 2 cpu's and 2048 MB RAM per node are required.

On all nodes

  • Edit hostname
  • Edit /etc/hosts file and add all nodes.
  • Edit /etc/fstab and uncomment SWAP partition
  • Edit /etc/initramfs-tools/conf.d/resume and uncomment swap uuid
  • Find swap unit using systemctl –type swap and mask it using systemctl mask xxx.swap.
SWAP must be deactivated!

todo: what about fw, selinux?

apt update && apt install apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

apt update && apt install -y kubelet kubeadm kubectl docker.io

systemctl enable docker

Only on master node

kubeadm init --apiserver-advertise-address 192.168.0.100 --pod-network-cidr=172.16.0.0/16

# REMEMBER JOIN TOKEN output from last command !!!!!!!!!!!!!!!!!

# when done execute as regular user
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# enable network addon
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Only on nodes except master

kubeadm join 192.168.0.100:6443 --token zbdvek.v8fnw7hw8xcdxk03 --discovery-token-ca-cert-hash sha256:724601e4cd00fd78312f1fbf3726b688e894fc88f2c25962f478e546a59929c7

API Token vergessen/abgelaufen?

kubeadm token create --print-join-command

Test on master node

kubectl run my-httpd --image=httpd --port=80
kubectl get pods -l app=demo
kubectl scale deployment [deployment] --replicas 3
kubectl exec -it my-httpd -- /bin/bash
kubectl set image deployment demo nginx=1.9.1
kubectl patch pod my-httpd --patch '{}'
kubectl delete pod myhttpd

Finally autostart

systemctl start kubelet
systemctl enable kubelet
systemctl start docker
systemctl start kubelet

Pod

apiVersion: v1
kind: Pod
metadata:
  name: demo
spec:
  containers:
  - image: nginx
    name: nginx
    imagePullPolicy: Always
kubectl create -f mypod.yml
kubectl delete pod demo

ReplicaSet

Update muss manuell vorgenommen werden (downtime).

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: Always
kubectl create -f myreplica.yml
kubectl delete replicaset demo

Deployment

Deployments nutzen intern replicaset und managen das rolling update von selbst.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    spec:
      containers:
      - name: nginx
        image: nginx
        imagePullPolicy: Always
        env:
        - name: VERSION
          value: "v1"
kubectl create -f mydeployment.yml
kubectl delete deployment demo

Persistent Volumes

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2

StatefulSet

todo

Volume types

  • Host based
    • EmptyDir
    • HostPath
  • Block Storage
    • Amazon EBS
    • GCE Persistent Disk
    • Azure Disk
    • vSphere Volume
  • Distributed file system
    • NFS
    • Ceph
    • Gluster
    • Amazon EFS
    • Azure File System
  • Other
    • Flocker
    • iSCSI
    • Git Repo
    • Quobyte
kubernetes.txt · Zuletzt geändert: 2024/02/20 09:56 (Externe Bearbeitung)