You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
6.6 KiB

  1. # Getting started
  2. ## Install ansible
  3. Install Ansible according to [Ansible installation guide](/docs/ansible/ansible.md#installing-ansible).
  4. ## Building your own inventory
  5. Ansible inventory can be stored in 3 formats: YAML, JSON, or INI-like. See the
  6. [example inventory](/inventory/sample/inventory.ini)
  7. and [Ansible documentation on building your inventory](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html),
  8. and [details on the inventory structure expected by Kubespray](/docs/ansible/inventory.md).
  9. ```ShellSession
  10. <your-favorite-editor> inventory/mycluster/inventory.ini
  11. # Review and change parameters under ``inventory/mycluster/group_vars``
  12. <your-favorite-editor> inventory/mycluster/group_vars/all.yml # for every node, including etcd
  13. <your-favorite-editor> inventory/mycluster/group_vars/k8s_cluster.yml # for every node in the cluster (not etcd when it's separate)
  14. <your-favorite-editor> inventory/mycluster/group_vars/kube_control_plane.yml # for the control plane
  15. <your-favorite-editor> inventory/myclsuter/group_vars/kube_node.yml # for worker nodes
  16. ```
  17. ## Installing the cluster
  18. ```ShellSession
  19. ansible-playbook -i inventory/mycluster/ cluster.yml -b -v \
  20. --private-key=~/.ssh/private_key
  21. ```
  22. ### Adding nodes
  23. You may want to add worker, control plane or etcd nodes to your existing cluster. This can be done by re-running the `cluster.yml` playbook, or you can target the bare minimum needed to get kubelet installed on the worker and talking to your control planes. This is especially helpful when doing something like autoscaling your clusters.
  24. - Add the new worker node to your inventory in the appropriate group (or utilize a [dynamic inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html)).
  25. - Run the ansible-playbook command, substituting `cluster.yml` for `scale.yml`:
  26. ```ShellSession
  27. ansible-playbook -i inventory/mycluster/hosts.yml scale.yml -b -v \
  28. --private-key=~/.ssh/private_key
  29. ```
  30. ### Remove nodes
  31. You may want to remove **control plane**, **worker**, or **etcd** nodes from your
  32. existing cluster. This can be done by re-running the `remove-node.yml`
  33. playbook. First, all specified nodes will be drained, then stop some
  34. kubernetes services and delete some certificates,
  35. and finally execute the kubectl command to delete these nodes.
  36. This can be combined with the add node function. This is generally helpful
  37. when doing something like autoscaling your clusters. Of course, if a node
  38. is not working, you can remove the node and install it again.
  39. Use `--extra-vars "node=<nodename>,<nodename2>"` to select the node(s) you want to delete.
  40. ```ShellSession
  41. ansible-playbook -i inventory/mycluster/hosts.yml remove-node.yml -b -v \
  42. --private-key=~/.ssh/private_key \
  43. --extra-vars "node=nodename,nodename2"
  44. ```
  45. If a node is completely unreachable by ssh, add `--extra-vars reset_nodes=false`
  46. to skip the node reset step. If one node is unavailable, but others you wish
  47. to remove are able to connect via SSH, you could set `reset_nodes=false` as a host
  48. var in inventory.
  49. ## Connecting to Kubernetes
  50. By default, Kubespray configures kube_control_plane hosts with insecure access to
  51. kube-apiserver via port 8080. A kubeconfig file is not necessary in this case,
  52. because kubectl will use <http://localhost:8080> to connect. The kubeconfig files
  53. generated will point to localhost (on kube_control_planes) and kube_node hosts will
  54. connect either to a localhost nginx proxy or to a loadbalancer if configured.
  55. More details on this process are in the [HA guide](/docs/operations/ha-mode.md).
  56. Kubespray permits connecting to the cluster remotely on any IP of any
  57. kube_control_plane host on port 6443 by default. However, this requires
  58. authentication. One can get a kubeconfig from kube_control_plane hosts
  59. (see [below](#accessing-kubernetes-api)).
  60. For more information on kubeconfig and accessing a Kubernetes cluster, refer to
  61. the Kubernetes [documentation](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/).
  62. ## Accessing Kubernetes Dashboard
  63. Supported version is kubernetes-dashboard v2.0.x :
  64. - Login option : token/kubeconfig by default
  65. - Deployed by default in "kube-system" namespace, can be overridden with `dashboard_namespace: kubernetes-dashboard` in inventory,
  66. - Only serves over https
  67. Access is described in [dashboard docs](https://github.com/kubernetes/dashboard/tree/master/docs/user/accessing-dashboard). With kubespray's default deployment in kube-system namespace, instead of kubernetes-dashboard :
  68. - Proxy URL is <http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#/login>
  69. - kubectl commands must be run with "-n kube-system"
  70. Accessing through Ingress is highly recommended. For proxy access, please note that proxy must listen to [localhost](https://github.com/kubernetes/dashboard/issues/692#issuecomment-220492484) (`proxy --address="x.x.x.x"` will not work)
  71. For token authentication, guide to create Service Account is provided in [dashboard sample user](https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md) doc. Still take care of default namespace.
  72. Access can also by achieved via ssh tunnel on a control plane :
  73. ```bash
  74. # localhost:8081 will be sent to control-plane-1's own localhost:8081
  75. ssh -L8001:localhost:8001 user@control-plane-1
  76. sudo -i
  77. kubectl proxy
  78. ```
  79. ## Accessing Kubernetes API
  80. The main client of Kubernetes is `kubectl`. It is installed on each kube_control_plane
  81. host and can optionally be configured on your ansible host by setting
  82. `kubectl_localhost: true` and `kubeconfig_localhost: true` in the configuration:
  83. - If `kubectl_localhost` enabled, `kubectl` will download onto `/usr/local/bin/` and setup with bash completion. A helper script `inventory/mycluster/artifacts/kubectl.sh` also created for setup with below `admin.conf`.
  84. - If `kubeconfig_localhost` enabled `admin.conf` will appear in the `inventory/mycluster/artifacts/` directory after deployment.
  85. - The location where these files are downloaded to can be configured via the `artifacts_dir` variable.
  86. NOTE: The controller host name in the admin.conf file might be a private IP. If so, change it to use the controller's public IP or the cluster's load balancer.
  87. You can see a list of nodes by running the following commands:
  88. ```ShellSession
  89. cd inventory/mycluster/artifacts
  90. ./kubectl.sh get nodes
  91. ```
  92. If desired, copy admin.conf to ~/.kube/config.
  93. ## Setting up your first cluster
  94. [Setting up your first cluster](/docs/getting_started/setting-up-your-first-cluster.md) is an
  95. applied step-by-step guide for setting up your first cluster with Kubespray.