kubernetesansiblekubespray

Is it possible to install only master when installing kubernetes with Kubespray?


I am trying to install kubernetes using kubespray.

I have successfully configured master and worker, but I wanted to know if only masters without workers could be installed. In inventory.ini, only the hostname of the master was specified and the installation proceeded, and the following failure message was displayed.

Is there a way to install only master excluding worker with kubespray? help!

    failed: [node1] (item=kube-node) => {
    "ansible_loop_var": "item",
    "assertion": "groups.get('kube-node')",
    "changed": false,
    "evaluated_to": false,
    "item": "kube-node",
    "msg": "Assertion failed"
}

Solution

  • You can try to use the ignore_assert_errors=yes option, I know this may sound like a workaround, but it seems to work as expected. I'm not sure if installing just single master node is covered somewhere in the kubespray documentation.


    I will create a simple example to illustrate how it works.

    Suppose I have one instance and I want it to be the Kubernetes master node:

    # ifconfig ens4
    ens4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1460
            inet 10.186.15.206  netmask 255.255.255.255  broadcast 10.186.15.206
        
    

    First, I've prepared the inventory file:

    # cat inventory/mycluster/hosts.yaml 
    all:
      hosts:
        node1:
          ansible_host: 10.186.15.206
          ip: 10.186.15.206
          access_ip: 10.186.15.206
      children:
        kube_control_plane:
          hosts:
            node1:
        kube-node:
          hosts: {}
        etcd:
          hosts:
            node1:
        k8s-cluster:
          children:
            kube_control_plane:
            kube-node:
        calico-rr:
          hosts: {}
      
      
    

    Then I've deployed Kubespray with Ansible Playbook:
    NOTE: I've used -e ignore_assert_errors=yes option.

    # ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root cluster.yml -e ignore_assert_errors=yes
    ...
    PLAY RECAP ***********************************************************************************************************************************************
    localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
    node1                      : ok=555  changed=121  unreachable=0    failed=0    skipped=1128 rescued=0    ignored=2 
    

    After successful installation we can check if node1 is really the master node:

    # kubectl get nodes
    NAME    STATUS   ROLES                  AGE     VERSION
    node1   Ready    control-plane,master   4m30s   v1.20.6
    
    # kubectl describe nodes node1 | grep -i taint
    Taints:             node-role.kubernetes.io/master:NoSchedule
    

    As you can see, node node1 has a node-role.kubernetes.io/master:NoSchedule taint indicating that it's indeed the master node.