0

Crear cluster de Kubernetes con K3D

Armando Serrano
Armando Serrano

Requerimientos:

  1. Linux PC 2cpu


Pasos a seguir:

  1. Instalar el binario k3d 
  2. Test k3d
  3. Iniciar cluster
  4. Cluster Info
  5. Listar nodos
  6. Listar pods
  7. Stop node



----------------------------------------------------------------------------------

Instalar el binario k3d 

### install wget ###

[root@localhost ~]#  yum install wget
Loaded plugins: fastestmirror
...
Installed:
  wget.x86_64 0:1.14-18.el7_6.1
Complete!


#### Instalar el binario k3d  ###

[root@localhost ~]#  wget -q -O - https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
Preparing to install k3d into /usr/local/bin
k3d installed into /usr/local/bin/k3d
Run 'k3d --help' to see what you can do with it.

######## Test k3d #####

[root@localhost ~]# k3d --help
https://k3d.io/
k3d is a wrapper CLI that helps you to easily create k3s clusters inside docker.
Nodes of a k3d cluster are docker containers running a k3s image.
All Nodes of a k3d cluster are part of the same docker network.
Usage:
  k3d [flags]
  k3d [command]Available Commands:
  cluster      Manage cluster(s)
  completion   Generate completion scripts for [bash, zsh, fish, powershell | psh]
  config       Work with config file(s)
  help         Help about any command
  image        Handle container images.
  kubeconfig   Manage kubeconfig(s)
  node         Manage node(s)
  registry     Manage registry/registries
  version      Show k3d and default k3s version
Flags:
  -h, --help         help for k3d
      --timestamps   Enable Log timestamps
      --trace        Enable super verbose output (trace logging)
      --verbose      Enable verbose output (debug logging)
      --version      Show k3d and default k3s version
Use "k3d [command] --help" for more information about a command.

Iniciar cluster

[root@localhost ~]# k3d cluster create digitalinnovation
INFO[0000] Prep: Network
INFO[0002] Created network 'k3d-digitalinnovation' (35d4a67361fdb1811077a2056e8f451d32fa199c98aa9cf07b0f357cbc5ca5b9)
INFO[0002] Created volume 'k3d-digitalinnovation-images'
INFO[0003] Creating node 'k3d-digitalinnovation-server-0'
INFO[0005] Pulling image 'docker.io/rancher/k3s:v1.20.6-k3s1'
INFO[0029] Creating LoadBalancer 'k3d-digitalinnovation-serverlb'
INFO[0031] Pulling image 'docker.io/rancher/k3d-proxy:v4.4.4'
INFO[0041] Starting cluster 'digitalinnovation'
INFO[0041] Starting servers...
INFO[0041] Starting Node 'k3d-digitalinnovation-server-0'
INFO[0068] Starting agents...
INFO[0068] Starting helpers...
INFO[0068] Starting Node 'k3d-digitalinnovation-serverlb'
INFO[0074] (Optional) Trying to get IP of the docker host and inject it into the cluster as 'host.k3d.internal' for easy access
INFO[0097] Successfully added host record to /etc/hosts in 2/2 nodes and to the CoreDNS ConfigMap
INFO[0097] Cluster 'digitalinnovation' created successfully!
INFO[0097] --kubeconfig-update-default=false --> sets --kubeconfig-switch-context=false
INFO[0097] You can now use it like this:
kubectl config use-context k3d-digitalinnovation
kubectl cluster-info

####### Cluster Info ######

[root@localhost ~]# kubectl cluster-info
Kubernetes master is running at https://0.0.0.0:45527
CoreDNS is running at https://0.0.0.0:45527/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://0.0.0.0:45527/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy


To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Listar nodos

[root@localhost ~]# kubectl get nodes
NAME                             STATUS   ROLES                  AGE     VERSION
k3d-digitalinnovation-server-0   Ready    control-plane,master   7m48s   v1.20.6+k3s1

Listar pods

[root@localhost ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                      READY   STATUS      RESTARTS   AGE
kube-system   metrics-server-86cbb8457f-p6rw7           1/1     Running     0          22m
kube-system   coredns-854c77959c-vbxhq                  1/1     Running     0          22m
kube-system   helm-install-traefik-dmkdz                0/1     Completed   0          22m
kube-system   svclb-traefik-pqshb                       2/2     Running     0          21m
kube-system   local-path-provisioner-5ff76fc89d-zg4kf   1/1     Running     1          22m
kube-system   traefik-6f9cbd9bd4-lvqwr                  1/1     Running     0          21m

Stop Node

[root@localhost ~]# k3d node stop k3d-digitalinnovation-server-0


https://k3d.io/usage/commands/k3d/


0
0

Comentários (0)