Also, you can create optional Grafana vm with prometeus on it.
For using it please do several things.
On this project public gitlab server is used. You should do things below:
- Create in CI/CD settings variable kube_config for storing kube config in the future.
- Create token for your account. This token will be used for deploying kube config at initial setup of cluster.
- Create repository for your code.
- Look at the cluster dir. There you can find all stuff for creating 3 vm in Gcloud. For using it you should add cred.json to this dir. Cred.json is a cred file which you generate in gcloud.
- You should change vars.tf with your project_id, region and zone.
- For using terraform code, you should do terraform init -> terraform plan -> terraform apply and 3 VMs will be created.
- After the last move you can find IP addresses of your VMs. You can connect to them using ssh and ec2-user login. These IP addresses should be placed to hosts file in kubernetes-ansible/centos directory.
- Add your token and gitlab project id to playbooks/env_variables.
- Run setup_master_node.yml for setting up your master node. You can comment "playbooks/configure_state_metrics.yml" line if you don't want to use optional monitoring vm in your lab system.
- Run setup_worker_nodes.yml for setting up your worker nodes.
- Now you can login to you master node and check cluster using "kubectl get nodes command" under root user for testing purposes.
NOW CLUSTER IS READY FOR DEPLOYING SERVICES.
- Look at the prom dir. There you can find all stuff for creating VM used for monitoring. For using it you should add cred.json to this dir. Cred.json is a cred file which you generate in gcloud.
- You should change vars.tf with your project_id, region and zone.
- For using terraform code, you should do terraform init -> terraform plan -> terraform apply and monitoring VM will be created.
- Add IP of the Grafana host to hosts file in kubernetes-ansible/centos directory.
- Run playbooks/configure_state_metrics.yml if you commented it in the step above.
- Run setup_prometheus.yml for setting up grafana node.
- Grafana's GUI is available at <PUBLIC_IP>:3000 address. You can use admin:admin for logging into interface. Change you password ASAP after starting service.
- For your kubecluster metrics being available you should make it available outside. I used hack redirecting traffic inside kube-metrics pod with firewalld rules. firewall-cmd --permanent --add-forward-port=port=4422:proto=tcp:toport=8080:toaddr=<CLUSTER_IP_ADDRESS>.
- Login to Grafana's GUI and add your prometeus as data sourse for Grafana.
- Add dashboard for Grafana. As for me, I chose 1860, 13332 and 6417, but You could choose any other dashboard or create your own.
For CI/CD purposes I've chosen gitlab.com. In test-project directory you can find helm chart for testing deployment. Yamllint, kubeval and kube-score are used for testing.
- Copy content of test-project dir to your gitlab's repository.
- Run pipeline or update gitlab's repository for automated start of .gitlab-ci.yml.