Kubernetes 104: Create a 2-node k3s cluster with k3sup


Create a 2-node k3s cluster with k3sup

Kubenetes-Master   = 192.168.17.5
Kubenetes-Worker  = 192.168.17.6
k3sup machine        = 192.168.1.131



!!!  Allow ssh access between k3sup  & two nodes of kubernetes
      and between two nodes of kubernetes.


!!!  Install K3SUP:
[root@devops ~]# curl -sLSf https://get.k3sup.dev | sh 
which: no k3sup in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
x86_64
Downloading package https://github.com/alexellis/k3sup/releases/download/0.3.0/k3sup as /tmp/k3sup
Download complete.

Running as root - Attempting to move k3sup to /usr/local/bin
New version of k3sup installed to /usr/local/bin
_    _____                 
| | _|___ / ___ _   _ _ __  
| |/ / |_ \/ __| | | | '_ \ 
|   < ___) \__ \ |_| | |_) |
|_|\_\____/|___/\__,_| .__/ 
                     |_|    
Version: 0.3.0
Git Commit: 7d954414def98c52ae1f6de08ac5317e4260e673
[root@devops ~]# 

!!! Install kubernetes master:

[root@devops ~]# export SERVER_IP=192.168.17.5
[root@devops ~]# k3sup install --ip $SERVER_IP --user root --local-path=./kubeconfig

Public IP: 192.168.17.5
ssh -i /root/.ssh/id_rsa root@192.168.17.5
ssh: curl -sLS https://get.k3s.io | INSTALL_K3S_EXEC='server --tls-san 192.168.17.5 ' INSTALL_K3S_VERSION='v0.8.1' sh -

[INFO]  Using v0.8.1 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.8.1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/rancher/k3s/releases/download/v0.8.1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
which: no kubectl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
which: no crictl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
which: no ctr in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s
Result: [INFO]  Using v0.8.1 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.8.1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/rancher/k3s/releases/download/v0.8.1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
[INFO]  systemd: Starting k3s
 which: no kubectl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
which: no crictl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
which: no ctr in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.

ssh: sudo cat /etc/rancher/k3s/k3s.yaml

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJWakNCL3FBREFnRUNBZ0VBTUFvR0NDcUdTTTQ5QkFNQ01DTXhJVEFmQmdOVkJBTU1HR3N6Y3kxelpYSjIKWlhJdFkyRkFNVFUyT1RNeU9EZ3dNekFlRncweE9UQTVNalF4TWpRd01ETmFGdzB5T1RBNU1qRXhNalF3TUROYQpNQ014SVRBZkJnTlZCQU1NR0dzemN5MXpaWEoyWlhJdFkyRkFNVFUyT1RNeU9EZ3dNekJaTUJNR0J5cUdTTTQ5CkFnRUdDQ3FHU000OUF3RUhBMElBQkRtcGlrR2hoN0ZtbGNzdUljbzM3L2hUSzRvS3lFZ0ttQjlxYkREMjI3NTYKREc1Mmd5TTBWbXhGV1M0VGpjcXR6ODYvZ1FXcEdzN2FTRWc3N3FjaTBrbWpJekFoTUE0R0ExVWREd0VCL3dRRQpBd0lDcERBUEJnTlZIUk1CQWY4RUJUQURBUUgvTUFvR0NDcUdTTTQ5QkFNQ0EwY0FNRVFDSUREOFJUcXd0ZTVaCjRWUDc5WFJjczlWam5sSi9VNVR5M2I4K1U3ZDV4SWtYQWlCMnlXdnVPSnYrazZMSzk3Qk5lWklSZklRdmZEanMKalJCUDBGNkZhZHB6dUE9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://localhost:6443
  name: default
contexts:
- context:
    cluster: default
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    password: 78b9464990a98098c4de1696f5396bfe
    username: admin
Result: apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJWakNCL3FBREFnRUNBZ0VBTUFvR0NDcUdTTTQ5QkFNQ01DTXhJVEFmQmdOVkJBTU1HR3N6Y3kxelpYSjIKWlhJdFkyRkFNVFUyT1RNeU9EZ3dNekFlRncweE9UQTVNalF4TWpRd01ETmFGdzB5T1RBNU1qRXhNalF3TUROYQpNQ014SVRBZkJnTlZCQU1NR0dzemN5MXpaWEoyWlhJdFkyRkFNVFUyT1RNeU9EZ3dNekJaTUJNR0J5cUdTTTQ5CkFnRUdDQ3FHU000OUF3RUhBMElBQkRtcGlrR2hoN0ZtbGNzdUljbzM3L2hUSzRvS3lFZ0ttQjlxYkREMjI3NTYKREc1Mmd5TTBWbXhGV1M0VGpjcXR6ODYvZ1FXcEdzN2FTRWc3N3FjaTBrbWpJekFoTUE0R0ExVWREd0VCL3dRRQpBd0lDcERBUEJnTlZIUk1CQWY4RUJUQURBUUgvTUFvR0NDcUdTTTQ5QkFNQ0EwY0FNRVFDSUREOFJUcXd0ZTVaCjRWUDc5WFJjczlWam5sSi9VNVR5M2I4K1U3ZDV4SWtYQWlCMnlXdnVPSnYrazZMSzk3Qk5lWklSZklRdmZEanMKalJCUDBGNkZhZHB6dUE9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://localhost:6443
  name: default
contexts:
- context:
    cluster: default
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    password: 78b9464990a98098c4de1696f5396bfe
    username: admin
 
Saving file to: /root/kubeconfig
[root@kmaster ~]# kubectl get node -o wide
NAME                  STATUS   ROLES    AGE   VERSION         INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
kmaster.cloud.local   Ready    master   22m   v1.14.6-k3s.1   192.168.17.5   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   containerd://1.2.7-k3s1


!!!  Install Kubernetes-Worker:
[root@devops ~]# export SERVER_IP=192.168.17.5
[root@devops ~]# export IP=192.168.17.6
[root@devops ~]# k3sup join --ip $IP --server-ip $SERVER_IP --user root

Server IP: 192.168.17.5
ssh -i /root/.ssh/id_rsa root@192.168.17.5
ssh: sudo cat /var/lib/rancher/k3s/server/node-token

K10f70feca0aba40bd0bf3cc10e9d3875e1360891bc7e86ab741d4bfb87b1240856::node:16d985abeafbe567c71ea382c39972a4
ssh: curl -sfL https://get.k3s.io/ | K3S_URL='https://192.168.17.5:6443' K3S_TOKEN='K10f70feca0aba40bd0bf3cc10e9d3875e1360891bc7e86ab741d4bfb87b1240856::node:16d985abeafbe567c71ea382c39972a4' INSTALL_K3S_VERSION='v0.8.1' sh -s - 
[INFO]  Using v0.8.1 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.8.1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/rancher/k3s/releases/download/v0.8.1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
which: no kubectl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
which: no crictl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
which: no ctr in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO]  systemd: Enabling k3s-agent unit
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s-agent.service to /etc/systemd/system/k3s-agent.service.
[INFO]  systemd: Starting k3s-agent
Logs: which: no kubectl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
which: no crictl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
which: no ctr in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s-agent.service to /etc/systemd/system/k3s-agent.service.
Output: [INFO]  Using v0.8.1 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.8.1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/rancher/k3s/releases/download/v0.8.1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO]  systemd: Enabling k3s-agent unit
[INFO]  systemd: Starting k3s-agent

[root@kmaster ~]# kubectl get node -o wide
NAME                  STATUS   ROLES    AGE   VERSION         INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
kmaster.cloud.local   Ready    master   22m   v1.14.6-k3s.1   192.168.17.5   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   containerd://1.2.7-k3s1
kworker.cloud.local   Ready    worker   78s   v1.14.6-k3s.1   192.168.17.6   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   containerd://1.2.7-k3s1

[root@kmaster ~]# kubectl describe node/kmaster.cloud.local
Name:               kmaster.cloud.local
Roles:              master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=kmaster.cloud.local
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/master=true
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"36:97:5d:52:bb:9c"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.17.5
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Tue, 24 Sep 2019 14:40:16 +0200
Taints:             <none>
Unschedulable:      false
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Tue, 24 Sep 2019 15:52:21 +0200   Tue, 24 Sep 2019 14:40:16 +0200   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Tue, 24 Sep 2019 15:52:21 +0200   Tue, 24 Sep 2019 14:40:16 +0200   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Tue, 24 Sep 2019 15:52:21 +0200   Tue, 24 Sep 2019 14:40:16 +0200   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Tue, 24 Sep 2019 15:52:21 +0200   Tue, 24 Sep 2019 14:40:27 +0200   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.17.5
  Hostname:    kmaster.cloud.local
Capacity:
 cpu:                4
 ephemeral-storage:  28289540Ki
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             2028116Ki
 pods:               110
Allocatable:
 cpu:                4
 ephemeral-storage:  27520064491
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             2028116Ki
 pods:               110
System Info:
 Machine ID:                 0b3a215670b149d5ae1a28a8c5df288a
 System UUID:                564D4823-4C94-50D2-A918-F7800144496D
 Boot ID:                    ecdda590-74c1-4a82-8404-d8b87523a0e6
 Kernel Version:             3.10.0-957.el7.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  containerd://1.2.7-k3s1
 Kubelet Version:            v1.14.6-k3s.1
 Kube-Proxy Version:         v1.14.6-k3s.1
PodCIDR:                     10.42.0.0/24
Non-terminated Pods:         (3 in total)
  Namespace                  Name                        CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                        ------------  ----------  ---------------  -------------  ---
  kube-system                coredns-b7464766c-wvvhb     100m (2%)     0 (0%)      70Mi (3%)        170Mi (8%)     72m
  kube-system                svclb-traefik-m57hg         0 (0%)        0 (0%)      0 (0%)           0 (0%)         69m
  kube-system                traefik-5c79b789c5-2p4cj    0 (0%)        0 (0%)      0 (0%)           0 (0%)         69m
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests   Limits
  --------           --------   ------
  cpu                100m (2%)  0 (0%)
  memory             70Mi (3%)  170Mi (8%)
  ephemeral-storage  0 (0%)     0 (0%)
Events:              <none>


[root@kmaster ~]# kubectl describe node/kworker.cloud.local
Name:               kworker.cloud.local
Roles:              worker
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=kworker.cloud.local
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/worker=true
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"2e:87:2e:3b:b5:88"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.17.6
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Tue, 24 Sep 2019 15:01:37 +0200
Taints:             <none>
Unschedulable:      false
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Tue, 24 Sep 2019 15:50:23 +0200   Tue, 24 Sep 2019 15:01:36 +0200   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Tue, 24 Sep 2019 15:50:23 +0200   Tue, 24 Sep 2019 15:01:36 +0200   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Tue, 24 Sep 2019 15:50:23 +0200   Tue, 24 Sep 2019 15:01:36 +0200   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Tue, 24 Sep 2019 15:50:23 +0200   Tue, 24 Sep 2019 15:01:44 +0200   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.17.6
  Hostname:    kworker.cloud.local
Capacity:
 cpu:                4
 ephemeral-storage:  28289540Ki
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             2028116Ki
 pods:               110
Allocatable:
 cpu:                4
 ephemeral-storage:  27520064491
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             2028116Ki
 pods:               110
System Info:
 Machine ID:                 0b3a215670b149d5ae1a28a8c5df288a
 System UUID:                564D33F6-0D86-737F-8876-CF8AD085B4BC
 Boot ID:                    999322f6-fa6e-4b61-85e7-5f72fe999d19
 Kernel Version:             3.10.0-957.el7.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  containerd://1.2.7-k3s1
 Kubelet Version:            v1.14.6-k3s.1
 Kube-Proxy Version:         v1.14.6-k3s.1
PodCIDR:                     10.42.1.0/24
Non-terminated Pods:         (1 in total)
  Namespace                  Name                   CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                   ------------  ----------  ---------------  -------------  ---
  kube-system                svclb-traefik-w6fds    0 (0%)        0 (0%)      0 (0%)           0 (0%)         49m
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests  Limits
  --------           --------  ------
  cpu                0 (0%)    0 (0%)
  memory             0 (0%)    0 (0%)
  ephemeral-storage  0 (0%)    0 (0%)
Events:
  Type     Reason                   Age   From                             Message
  ----     ------                   ----  ----                             -------
  Normal   Starting                 49m   kubelet, kworker.cloud.local     Starting kubelet.
  Warning  InvalidDiskCapacity      49m   kubelet, kworker.cloud.local     invalid capacity 0 on image filesystem
  Normal   NodeHasSufficientMemory  49m   kubelet, kworker.cloud.local     Node kworker.cloud.local status is now: NodeHasSufficientMemory
  Normal   Starting                 49m   kubelet, kworker.cloud.local     Starting kubelet.
  Warning  InvalidDiskCapacity      49m   kubelet, kworker.cloud.local     invalid capacity 0 on image filesystem
  Normal   NodeHasSufficientMemory  49m   kubelet, kworker.cloud.local     Node kworker.cloud.local status is now: NodeHasSufficientMemory
  Normal   NodeHasNoDiskPressure    49m   kubelet, kworker.cloud.local     Node kworker.cloud.local status is now: NodeHasNoDiskPressure
  Normal   NodeHasSufficientPID     49m   kubelet, kworker.cloud.local     Node kworker.cloud.local status is now: NodeHasSufficientPID
  Normal   Starting                 49m   kube-proxy, kworker.cloud.local  Starting kube-proxy.
  Normal   NodeAllocatableEnforced  49m   kubelet, kworker.cloud.local     Updated Node Allocatable limit across pods
  Normal   NodeReady                49m   kubelet, kworker.cloud.local     Node kworker.cloud.local status is now: NodeReady


================================================================
Good Luck https://www.linkedin.com/in/ahmedms/


















Comments

Post a Comment

Popular posts from this blog

DevNet 103: Network Automation Using Python

How to configure OSPF on Palo Alto Networks Firewall?