Skip to content

Kubernetes

Mehdi Hadeli edited this page Sep 18, 2023 · 62 revisions

Kubernetes

Resources

Articles

Notes

  • kubernetes supports substitute and replace environment variable in kubernetes resource files but it only works for env section of our resource, actually we can use $(VAR_NAME) in the value of env attribute in the resource file. but we want to use environment variables in all attribute so we use envsubst approach. Then define these environment variables either by defining them in the shell session (will destroy after closing shell) or save them to a file (e.g. .env)
export SERVER_URL=https://gitlab.com/test
export USER_NAME=foo_user
export USER_PASSWORD=test

then loading them into your current shell session by using source .env, then our resource will substitute with envsubst < input.tmpl > output.text (it is also possible to write your substitution to a new file). It is possible to pipe the output into other commands like less or kubectl for Kubernetes for example envsubst < deploy.yml | kubectl apply -f -.

  • load balancer service type for choosing one node on the cluster and connect to node port on the cluster node, if we want for each service in our node create a separated load balancer service type it should allocate separate ip for that and with this ip connect to a node port on the cluster and then connect to internal service and container and it is expensive.
  • if we have to add one more service to our node and access it from another URL. In this case, we will have to add another load balancer to our cluster. This means that each service exposed with a LoadBalancer will get its own IP address and we will have to pay for each of these load balancers which can be quite expensive.
  • Ingress is not actually a type of service. Instead, it is an entry point that sits in front of multiple services in the cluster. It can be defined as a collection of routing rules that govern how external users access services running inside a Kubernetes cluster.
  • we use traefik behind a load balancer service type, for load balancing between nodes and then use ingress for route traefik internal to each node
  • According to the Kubernetes documentation, it is recommended to put resources related to the same microservice or application tier into the same file[1]. This helps in organizing and managing resources more efficiently. It also makes it easier to understand and maintain the configuration files.
  • we can skip the company.com prefix if we don’t intend to distribute our resources outside of our company (as long as we don’t expect a naming conflict with another third-party package installed in our environment using the same label without a prefix).
  • we can visualize and manage Kubernetes objects with more tools than kubectl and the dashboard. A common set of labels allows tools to work interoperably, describing objects in a common manner that all tools can understand.
  • Shared labels and annotations share a common prefix: app.kubernetes.io. Labels without a prefix are private to users. The shared prefix ensures that shared labels do not interfere with custom user labels.
  • The .spec.selector field in deployment defines how the created ReplicaSet finds which Pods to manage. In this case, we use set-based label selector to select matchLabels labels, and finding pods for these labels (pods labels defined in the pod template section)
  • matchLabels is a Set-based label selector
  • matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of `matchExpressions``, whose key field is "key", the operator is "In", and the values array contains only "value".
  • find resources with label selector kubectl get pods -l environment=production,tier=frontend
  • kubectl port-forward allows using resource name, such as a pod name or service name, and forwards its port to local port or actually http://127.0.0.1:<Forward_Port> or http://localhost:<Forward_Port> or localhost ping -> [::1]:<Forward_Port>

Tools

Videos

Samples

Validation

Kustomize

Articles

Videos

Samples

Helm

Articles

Videos

Samples

Clone this wiki locally