Skip to content

Instantly share code, notes, and snippets.

View denzhel's full-sized avatar
🇺🇦

Dennis Zheleznyak denzhel

🇺🇦
View GitHub Profile
@denzhel
denzhel / kibana_on_k8s.md
Created May 6, 2021 05:56
Use Kibana in your Kubernetes Cluster

To launch a temporary Kibana pod you can use the following:

k run -i --tty --rm --image=kibana:6.8.15 --env="ELASTICSEARCH_URL=http://<ServiceNameOfElasticSearchPod>:9200" --port=5601 kibana
k port-forward pod/kibana 5601:5601

Then you can browse Safari/ Chrome/ Firefox and access localhost:5601

@denzhel
denzhel / limit_k8s_ns.md
Last active June 30, 2021 06:48
Limit number of K8s namespaces per user

We use a wrapper script to allow the developers to fire up K8s namespaces with all the deployments. Sometimes, they exaggerate and open a lot of them.

I wrote this function to limit the number of namespaces they can open. The scripts assumes each namespaces has a label with the owner tag.

function limit_namespaces_per_user() {
	# Define the user and how many namespaces to allow per user
	local ALLOWED_NS="${1}"
@denzhel
denzhel / ansible_with_items_dict.md
Last active August 2, 2021 15:08
Loop through a dictionary in Ansible

To loop through a dictionary in ansible, you can use the following:

- name: "{{ nginx_name }} | configure nginx by templating the config files"
      template:
        src: "{{ item.source }}"
        dest: "{{ item.destination }}"
        mode: "0644"
      with_items:
        - { source: "nginx.conf.j2", destination: "{{nginx_conf_dir}}/nginx.conf" }
 - { source: "fastcgi_params.j2", destination: "{{nginx_conf_dir}}/fastcgi_params" }
@denzhel
denzhel / es_disk_water_marks.md
Created July 1, 2021 03:23
Elasticsearch Disk Watermarks

If you want to configure water marks or you are getting these errors:

low disk watermark [85%] exceeded on [XXXXXXX][prod-elasticsearch-13] free: 209.9gb[14.2%], replicas will not be assigned to this node

Consider changing the limits by using this command:

curl -XPUT 'http://localhost:9200/_cluster/settings' -H 'Content-Type: application/json' -d '{ 
"transient" : { 
"cluster.routing.allocation.disk.watermark.flood_stage" : "99%",
"cluster.routing.allocation.disk.watermark.low" : "90%",
@denzhel
denzhel / vim_trailing_spaces.md
Created July 10, 2021 19:29
Auto remove yaml trailing spaces in Vim

I use this config to automatically remove trailing spaces in my yaml files:

autocmd BufWritePre *.c,*.php :%s/\s\+$//ge

#ansible #vim #terraform

@denzhel
denzhel / kafka_list_topics.md
Last active July 20, 2021 18:01
List all kafka topics

To list all Kafka topics in our cluster, use the following commaand:

./kafka-topics.sh --zookeeper <ZooKeeperHost>:2181 --list

#kafka

@denzhel
denzhel / consume_kafka_msgs.md
Last active July 20, 2021 18:01
Consume Kafka messages

If you don't have Kafkacat installed you can use the default tools installed with the server:

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic <TopicNaame> --from-beginning

#kafka

@denzhel
denzhel / destroy_multiple_terraform.md
Last active August 2, 2021 17:59
Apply or Destroy Terraform resources

If you want to destroy something from your state that has a lot of resources with a common name you can use the following:

terraform apply $(for i in $(tf state list | grep <Name>); do echo -n "-target=$i " ; done) 

e.g I use it to destroy a datastore that has many resources such as EC2, Route53 records, EBS and etc ..

#terraform

@denzhel
denzhel / remove_new_line_vim.md
Created August 15, 2021 04:13
remove new line in vim

Since I use VIM as my main IDE, alot of times I have to remove the new line that is added to files when I edit them. To do that, edit the file you are working on and type the following:

:set noendofline binary
:wq!
@denzhel
denzhel / helm_hosts_with_ports.md
Created August 19, 2021 06:32
helm helper function: hosts with ports

The following function takes a map of hosts and ports:

  datastores:
    db:
      database: data
      replicaSet: mongo
      servers:
      - host: a
        port: 27017
 - host: b