kubernetes:gyakorlatok
Különbségek
A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
| Előző változat mindkét oldalonElőző változatKövetkező változat | Előző változat | ||
| kubernetes:gyakorlatok [2025/09/17 09:55] – riba.zoltan | kubernetes:gyakorlatok [2025/10/07 15:56] (aktuális) – riba.zoltan | ||
|---|---|---|---|
| Sor 1: | Sor 1: | ||
| + | ===== Kubernetes klaszter telepítése ===== | ||
| + | |||
| + | A telepített környezet három virtuális gépből áll: | ||
| + | |||
| + | * *kube01* (control plane): Almalinux 10 (x86_64), minimal install (VCPU: 2, RAM: 3 GB, DISK: 20 GB) | ||
| + | * *kube02* (worker): Almalinux 10 (x86_64), minimal install (VCPU: 2, RAM: 4 GB, DISK: 20 GB) | ||
| + | * *kube03* (worker): Almalinux 10 (x86_64), minimal install (VCPU: 2, RAM: 4 GB, DISK: 20 GB) | ||
| + | |||
| + | A telepítéskor ne adjunk swap területet. | ||
| + | |||
| + | ==== Telepítést követő lépések ==== | ||
| + | |||
| + | Az alábbi utasításokat a klaszter összes gépén le kell futtatni. | ||
| + | |||
| + | SElinux megengedő módba kapcsolása | ||
| + | |||
| + | < | ||
| + | # sed -i ' | ||
| + | |||
| + | # setenforce 0 | ||
| + | </ | ||
| + | |||
| + | Tűzfal szolgáltatás kikapcsolása és tiltása | ||
| + | |||
| + | < | ||
| + | # systemctl disable firewalld | ||
| + | Removed '/ | ||
| + | Removed '/ | ||
| + | |||
| + | # systemctl stop firewalld | ||
| + | </ | ||
| + | |||
| + | Hosts állományok módosítása | ||
| + | |||
| + | < | ||
| + | # cat > /etc/hosts <<' | ||
| + | 127.0.0.1 | ||
| + | ::1 | ||
| + | |||
| + | 192.168.110.161 kube01 | ||
| + | 192.168.110.162 kube02 | ||
| + | 192.168.110.163 kube03 | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | Modulok betöltése | ||
| + | |||
| + | < | ||
| + | # cat > / | ||
| + | br_netfilter | ||
| + | overlay | ||
| + | EOF | ||
| + | |||
| + | # modprobe br_netfilter | ||
| + | |||
| + | # modprobe overlay | ||
| + | </ | ||
| + | |||
| + | Kernel hálózati paraméterek módosítása | ||
| + | |||
| + | < | ||
| + | # cat > / | ||
| + | net.ipv4.ip_forward = 1 | ||
| + | net.bridge.bridge-nf-call-ip6tables = 1 | ||
| + | net.bridge.bridge-nf-call-iptables = 1 | ||
| + | EOF | ||
| + | |||
| + | # sysctl --system | ||
| + | </ | ||
| + | |||
| + | SWAP tiltása | ||
| + | |||
| + | < | ||
| + | # sed -i '/ swap / s/ | ||
| + | |||
| + | # systemctl daemon-reload | ||
| + | |||
| + | # swapoff -a | ||
| + | </ | ||
| + | |||
| + | Containerd repo telepítése | ||
| + | |||
| + | < | ||
| + | # curl -L -o / | ||
| + | </ | ||
| + | |||
| + | Kubernetes repo létrehozása | ||
| + | |||
| + | < | ||
| + | # cat > / | ||
| + | [kubernetes] | ||
| + | name=Kubernetes | ||
| + | baseurl=https:// | ||
| + | enabled=1 | ||
| + | gpgcheck=1 | ||
| + | gpgkey=https:// | ||
| + | exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | Containerd telepítése | ||
| + | |||
| + | < | ||
| + | # dnf install containerd | ||
| + | </ | ||
| + | |||
| + | Containerd konfiguráció mentése | ||
| + | |||
| + | < | ||
| + | # cp -a / | ||
| + | </ | ||
| + | |||
| + | Containerd konfiguráció készítése | ||
| + | |||
| + | < | ||
| + | # containerd config default > / | ||
| + | </ | ||
| + | |||
| + | Containerd konfiguráció módosítása | ||
| + | |||
| + | < | ||
| + | # grep pause:3 / | ||
| + | sandbox_image = " | ||
| + | |||
| + | # sed -i ' | ||
| + | |||
| + | # grep pause:3 / | ||
| + | sandbox_image = " | ||
| + | |||
| + | # grep SystemdCgroup / | ||
| + | SystemdCgroup = false | ||
| + | |||
| + | # sed -i ' | ||
| + | |||
| + | # grep SystemdCgroup / | ||
| + | SystemdCgroup = true | ||
| + | </ | ||
| + | |||
| + | Containerd engedélyezése és indítása | ||
| + | |||
| + | < | ||
| + | # systemctl --now enable containerd | ||
| + | Created symlink '/ | ||
| + | </ | ||
| + | |||
| + | Kubernetes klaszterhez szükséges csomagok telepítése | ||
| + | |||
| + | < | ||
| + | # dnf --disableexcludes=kubernetes install kubeadm kubectl kubelet | ||
| + | </ | ||
| + | |||
| + | Kubernetes kubelet szolgáltatás engedélyezése | ||
| + | |||
| + | < | ||
| + | # systemctl enable kubelet | ||
| + | </ | ||
| + | |||
| + | ==== Control plane konfigurálása ==== | ||
| + | |||
| + | Az alábbi utasításokat a control plane gépen kell futtatni | ||
| + | |||
| + | Klaszter init meghívása | ||
| + | |||
| + | < | ||
| + | # kubeadm init --pod-network-cidr=10.244.0.0/ | ||
| + | [init] Using Kubernetes version: v1.34.1 | ||
| + | [preflight] Running pre-flight checks | ||
| + | [preflight] Pulling images required for setting up a Kubernetes cluster | ||
| + | [preflight] This might take a minute or two, depending on the speed of your internet connection | ||
| + | [preflight] You can also perform this action beforehand using ' | ||
| + | [certs] Using certificateDir folder "/ | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [certs] apiserver serving cert is signed for DNS names [kube01 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.110.161] | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [certs] etcd/server serving cert is signed for DNS names [kube01 localhost] and IPs [192.168.110.161 127.0.0.1 ::1] | ||
| + | [certs] Generating " | ||
| + | [certs] etcd/peer serving cert is signed for DNS names [kube01 localhost] and IPs [192.168.110.161 127.0.0.1 ::1] | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [certs] Generating " | ||
| + | [kubeconfig] Using kubeconfig folder "/ | ||
| + | [kubeconfig] Writing " | ||
| + | [kubeconfig] Writing " | ||
| + | [kubeconfig] Writing " | ||
| + | [kubeconfig] Writing " | ||
| + | [kubeconfig] Writing " | ||
| + | [etcd] Creating static Pod manifest for local etcd in "/ | ||
| + | [control-plane] Using manifest folder "/ | ||
| + | [control-plane] Creating static Pod manifest for " | ||
| + | [control-plane] Creating static Pod manifest for " | ||
| + | [control-plane] Creating static Pod manifest for " | ||
| + | [kubelet-start] Writing kubelet environment file with flags to file "/ | ||
| + | [kubelet-start] Writing kubelet configuration to file "/ | ||
| + | [patches] Applied patch of type " | ||
| + | [kubelet-start] Writing kubelet configuration to file "/ | ||
| + | [kubelet-start] Starting the kubelet | ||
| + | [wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/ | ||
| + | [kubelet-check] Waiting for a healthy kubelet at http:// | ||
| + | [kubelet-check] The kubelet is healthy after 1.50097886s | ||
| + | [control-plane-check] Waiting for healthy control plane components. This can take up to 4m0s | ||
| + | [control-plane-check] Checking kube-apiserver at https:// | ||
| + | [control-plane-check] Checking kube-controller-manager at https:// | ||
| + | [control-plane-check] Checking kube-scheduler at https:// | ||
| + | [control-plane-check] kube-controller-manager is healthy after 3.507200493s | ||
| + | [control-plane-check] kube-scheduler is healthy after 4.632817046s | ||
| + | [control-plane-check] kube-apiserver is healthy after 11.004003859s | ||
| + | [upload-config] Storing the configuration used in ConfigMap " | ||
| + | [kubelet] Creating a ConfigMap " | ||
| + | [upload-certs] Skipping phase. Please see --upload-certs | ||
| + | [mark-control-plane] Marking the node kube01 as control-plane by adding the labels: [node-role.kubernetes.io/ | ||
| + | [mark-control-plane] Marking the node kube01 as control-plane by adding the taints [node-role.kubernetes.io/ | ||
| + | [bootstrap-token] Using token: is490j.gmk4mrbp5aum3q8y | ||
| + | [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles | ||
| + | [bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes | ||
| + | [bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials | ||
| + | [bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token | ||
| + | [bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster | ||
| + | [bootstrap-token] Creating the " | ||
| + | [kubelet-finalize] Updating "/ | ||
| + | [addons] Applied essential addon: CoreDNS | ||
| + | [addons] Applied essential addon: kube-proxy | ||
| + | |||
| + | Your Kubernetes control-plane has initialized successfully! | ||
| + | |||
| + | To start using your cluster, you need to run the following as a regular user: | ||
| + | |||
| + | mkdir -p $HOME/.kube | ||
| + | sudo cp -i / | ||
| + | sudo chown $(id -u):$(id -g) $HOME/ | ||
| + | |||
| + | Alternatively, | ||
| + | |||
| + | export KUBECONFIG=/ | ||
| + | |||
| + | You should now deploy a pod network to the cluster. | ||
| + | Run " | ||
| + | https:// | ||
| + | |||
| + | Then you can join any number of worker nodes by running the following on each as root: | ||
| + | kubeadm join 192.168.110.171: | ||
| + | </ | ||
| + | |||
| + | A kapcsolódáshoz szükséges konfiguráció beállítása | ||
| + | |||
| + | < | ||
| + | # mkdir -p $HOME/.kube | ||
| + | |||
| + | # sudo cp -i / | ||
| + | |||
| + | # sudo chown $(id -u):$(id -g) $HOME/ | ||
| + | </ | ||
| + | |||
| + | Működés ellenőrzése | ||
| + | |||
| + | < | ||
| + | # kubectl get nodes | ||
| + | NAME | ||
| + | kube01 | ||
| + | </ | ||
| + | |||
| + | Pod hálózat létrehozása (Flannel) | ||
| + | |||
| + | < | ||
| + | # kubectl apply -f https:// | ||
| + | namespace/ | ||
| + | serviceaccount/ | ||
| + | clusterrole.rbac.authorization.k8s.io/ | ||
| + | clusterrolebinding.rbac.authorization.k8s.io/ | ||
| + | configmap/ | ||
| + | daemonset.apps/ | ||
| + | </ | ||
| + | |||
| + | Rövid idő elteltével újabb ellenőrzés | ||
| + | |||
| + | < | ||
| + | # kubectl get nodes | ||
| + | NAME | ||
| + | kube01 | ||
| + | </ | ||
| + | |||
| + | ==== Worker gépek csatlakoztatása ==== | ||
| + | |||
| + | Az alábbi utasításokat a worker gépeken kell futtatni | ||
| + | |||
| + | < | ||
| + | # kubeadm join 192.168.110.161: | ||
| + | [preflight] Running pre-flight checks | ||
| + | [preflight] Reading configuration from the " | ||
| + | [preflight] Use ' | ||
| + | [kubelet-start] Writing kubelet configuration to file "/ | ||
| + | [patches] Applied patch of type " | ||
| + | [kubelet-start] Writing kubelet configuration to file "/ | ||
| + | [kubelet-start] Writing kubelet environment file with flags to file "/ | ||
| + | [kubelet-start] Starting the kubelet | ||
| + | [kubelet-check] Waiting for a healthy kubelet at http:// | ||
| + | [kubelet-check] The kubelet is healthy after 1.004029985s | ||
| + | [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap | ||
| + | |||
| + | This node has joined the cluster: | ||
| + | * Certificate signing request was sent to apiserver and a response was received. | ||
| + | * The Kubelet was informed of the new secure connection details. | ||
| + | |||
| + | Run ' | ||
| + | </ | ||
| + | |||
| + | ==== Klaszter ellenőrzése ==== | ||
| + | |||
| + | A klaszter ellenőrzését a control plane gépen végezzük el | ||
| + | |||
| + | < | ||
| + | # kubectl get nodes | ||
| + | NAME | ||
| + | kube01 | ||
| + | kube02 | ||
| + | kube03 | ||
| + | </ | ||
| + | |||
| ====== Pod ====== | ====== Pod ====== | ||
| + | |||
| Pod erőforás dokumentáció megjelenítése | Pod erőforás dokumentáció megjelenítése | ||
| + | |||
| < | < | ||
| # kubectl explain pod | # kubectl explain pod | ||
| Sor 8: | Sor 332: | ||
| < | < | ||
| - | # kubectl run nginx-pod --image=registry.r-l.hu/ | + | # kubectl run nginx-pod --image=nginx: |
| </ | </ | ||
| Sor 22: | Sor 346: | ||
| containers: | containers: | ||
| - name: nginx | - name: nginx | ||
| - | image: | + | image: nginx: |
| EOF | EOF | ||
| </ | </ | ||
| Sor 59: | Sor 383: | ||
| nginx-pod: | nginx-pod: | ||
| Container ID: | Container ID: | ||
| - | Image: | + | Image: |
| - | Image ID: registry.r-l.hu/ | + | Image ID: |
| Port: < | Port: < | ||
| Host Port: < | Host Port: < | ||
| Sor 92: | Sor 416: | ||
| ---- ------ | ---- ------ | ||
| Normal | Normal | ||
| - | Normal | + | Normal |
| - | Normal | + | Normal |
| Normal | Normal | ||
| Normal | Normal | ||
| Sor 137: | Sor 461: | ||
| containers: | containers: | ||
| - name: nginx | - name: nginx | ||
| - | image: | + | image: nginx:1.25 |
| ports: | ports: | ||
| - containerPort: | - containerPort: | ||
| Sor 177: | Sor 501: | ||
| < | < | ||
| - | # kubectl run debug-pod --rm -it --image=registry.r-l.hu/ | + | # kubectl run debug-pod --rm -it --image=busybox: |
| </ | </ | ||
| Sor 188: | Sor 512: | ||
| < | < | ||
| - | # kubectl create deployment nginx-deployment --image=registry.r-l.hu/ | + | # kubectl create deployment nginx-deployment --image=nginx: |
| deployment.apps/ | deployment.apps/ | ||
| deployment.apps/ | deployment.apps/ | ||
| Sor 224: | Sor 548: | ||
| containers: | containers: | ||
| - name: nginx | - name: nginx | ||
| - | image: | + | image: nginx:1.25 |
| ports: | ports: | ||
| - containerPort: | - containerPort: | ||
| Sor 239: | Sor 563: | ||
| deployment.apps/ | deployment.apps/ | ||
| - | # kubectl set image deployment/ | + | # kubectl set image deployment/ |
| deployment.apps/ | deployment.apps/ | ||
| Sor 262: | Sor 586: | ||
| deployment.apps/ | deployment.apps/ | ||
| - | # kubectl set image deployment/ | + | # kubectl set image deployment/ |
| deployment.apps/ | deployment.apps/ | ||
| Sor 287: | Sor 611: | ||
| kubectl get replicasets -o wide | kubectl get replicasets -o wide | ||
| NAME DESIRED | NAME DESIRED | ||
| - | nginx-deployment-6585597c84 | + | nginx-deployment-6585597c84 |
| - | nginx-deployment-6ccb84987c | + | nginx-deployment-6ccb84987c |
| - | nginx-deployment-7bdc5996d7 | + | nginx-deployment-7bdc5996d7 |
| </ | </ | ||
| Sor 300: | Sor 624: | ||
| # kubectl get replicasets -o wide | # kubectl get replicasets -o wide | ||
| NAME DESIRED | NAME DESIRED | ||
| - | nginx-deployment-6585597c84 | + | nginx-deployment-6585597c84 |
| - | nginx-deployment-6ccb84987c | + | nginx-deployment-6ccb84987c |
| - | nginx-deployment-7bdc5996d7 | + | nginx-deployment-7bdc5996d7 |
| </ | </ | ||
| Sor 570: | Sor 894: | ||
| < | < | ||
| - | # podman image tag localhost/ | + | # podman image tag localhost/ |
| - | # podman push registry.r-l.hu/ | + | # podman push REGISTRY_URL/ |
| Getting image source signatures | Getting image source signatures | ||
| Copying blob cba3fb5670d7 done | Copying blob cba3fb5670d7 done | ||
| Sor 626: | Sor 950: | ||
| containers: | containers: | ||
| - name: app | - name: app | ||
| - | image: | + | image: |
| imagePullPolicy: | imagePullPolicy: | ||
| ports: | ports: | ||
| Sor 755: | Sor 1079: | ||
| replicaset.apps/ | replicaset.apps/ | ||
| replicaset.apps/ | replicaset.apps/ | ||
| + | </ | ||
| + | |||
| + | ====== Kubernetes natív LB megoldás ====== | ||
| + | |||
| + | A konfigurálást a control plane gépen végezzük el | ||
| + | |||
| + | MetalLB telepítése | ||
| + | |||
| + | < | ||
| + | # kubectl apply -f https:// | ||
| + | namespace/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | customresourcedefinition.apiextensions.k8s.io/ | ||
| + | serviceaccount/ | ||
| + | serviceaccount/ | ||
| + | role.rbac.authorization.k8s.io/ | ||
| + | role.rbac.authorization.k8s.io/ | ||
| + | clusterrole.rbac.authorization.k8s.io/ | ||
| + | clusterrole.rbac.authorization.k8s.io/ | ||
| + | rolebinding.rbac.authorization.k8s.io/ | ||
| + | rolebinding.rbac.authorization.k8s.io/ | ||
| + | clusterrolebinding.rbac.authorization.k8s.io/ | ||
| + | clusterrolebinding.rbac.authorization.k8s.io/ | ||
| + | configmap/ | ||
| + | secret/ | ||
| + | service/ | ||
| + | deployment.apps/ | ||
| + | daemonset.apps/ | ||
| + | validatingwebhookconfiguration.admissionregistration.k8s.io/ | ||
| + | </ | ||
| + | |||
| + | Publikus IP tartomány megadása | ||
| + | |||
| + | < | ||
| + | # cat > ~/ | ||
| + | apiVersion: metallb.io/ | ||
| + | kind: IPAddressPool | ||
| + | metadata: | ||
| + | name: pool-l2 | ||
| + | namespace: metallb-system | ||
| + | spec: | ||
| + | addresses: | ||
| + | - 192.168.110.170-192.168.110.179 | ||
| + | --- | ||
| + | apiVersion: metallb.io/ | ||
| + | kind: L2Advertisement | ||
| + | metadata: | ||
| + | name: l2adv | ||
| + | namespace: metallb-system | ||
| + | spec: | ||
| + | ipAddressPools: | ||
| + | - pool-l2 | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | MetalLB podjainak ellenőrzése | ||
| + | |||
| + | < | ||
| + | # kubectl -n metallb-system get pods | ||
| + | NAME READY | ||
| + | controller-7dbf649dcc-w4frr | ||
| + | speaker-4nkqt | ||
| + | speaker-q4h2p | ||
| + | speaker-vxp69 | ||
| + | </ | ||
| + | |||
| + | Konfiguráció alkalmazása (amennyiben a pod-ok Ready/ | ||
| + | |||
| + | < | ||
| + | # kubectl apply -f metallb-l2.yaml | ||
| + | ipaddresspool.metallb.io/ | ||
| + | l2advertisement.metallb.io/ | ||
| + | </ | ||
| + | |||
| + | A metallb-system névtér ellenőrzése | ||
| + | |||
| + | < | ||
| + | # kubectl get all -n metallb-system | ||
| + | NAME READY | ||
| + | pod/ | ||
| + | pod/ | ||
| + | pod/ | ||
| + | pod/ | ||
| + | |||
| + | NAME TYPE CLUSTER-IP | ||
| + | service/ | ||
| + | |||
| + | NAME | ||
| + | daemonset.apps/ | ||
| + | |||
| + | NAME | ||
| + | deployment.apps/ | ||
| + | |||
| + | NAME DESIRED | ||
| + | replicaset.apps/ | ||
| + | </ | ||
| + | |||
| + | Teszt deployment létrehozása és ellenőrzése | ||
| + | |||
| + | < | ||
| + | # kubectl create deploy nginx --image=nginx: | ||
| + | deployment.apps/ | ||
| + | |||
| + | # kubectl expose deploy nginx --type=LoadBalancer --port=80 --target-port=80 | ||
| + | service/ | ||
| + | |||
| + | # kubectl get svc nginx | ||
| + | NAME TYPE | ||
| + | nginx | ||
| + | </ | ||
| + | |||
| + | Amennyiben megjelent az EXTERNAL-IP oszlopban a definiált tartomány egyik IP címe, akkor tesztelhető a szolgáltatás | ||
| + | |||
| + | < | ||
| + | HTTP/1.1 200 OK | ||
| + | Server: nginx/ | ||
| + | Date: Thu, 25 Sep 2025 17:17:34 GMT | ||
| + | Content-Type: | ||
| + | Content-Length: | ||
| + | Last-Modified: | ||
| + | Connection: keep-alive | ||
| + | ETag: " | ||
| + | Accept-Ranges: | ||
| </ | </ | ||
kubernetes/gyakorlatok.1758102916.txt.gz · Utolsó módosítás: szerkesztette: riba.zoltan
