We have previously discussed how to deploy an Ingress access layer that provides high reliability in a Kubernetes cluster in the article Best Practices for Deploying a High-Reliability Kubernetes Ingress Controller. Ingress manages external access to services in a Kubernetes cluster. The Ingress Controller records request logs that are very important for tracking the entire request link. The following content describes how to import the collected Kubernetes Ingress Controller logs to Log Service to facilitate retrieval and analysis of service requests.
Perform the following steps to import the collected Ingress Controller logs to Log Service:
For more information, read our documentation.
Note: Skip this step if you have deployed Logtail DaemonSet in the cluster.
curl http://logtail-release.oss-cn-hangzhou.aliyuncs.com/docker/k8s/logtail-daemonset.yaml > logtail-daemonset.yaml
# Modify the following configuration items according to your environment.
vim logtail-daemonset.yaml
...
env:
- name: "ALIYUN_LOGTAIL_CONFIG"
value: "/etc/ilogtail/conf/${your_region_name}/ilogtail_config.json"
- name: "ALIYUN_LOGTAIL_USER_ID"
value: "${your_aliyun_user_id}"
- name: "ALIYUN_LOGTAIL_USER_DEFINED_ID"
value: "${your_machine_group_name}"
...
kubectl apply -f logtail-daemonset.yaml
daemonset "logtail" created
kubectl -n kube-system get pod | grep logtail
logtail-nbpl8 1/1 Running 0 52s
logtail-nr9hf 1/1 Running 0 52s
The configuration items are described as follows:
Note: Skip this step if you have created a project for collecting the Kubernetes cluster logs in the corresponding region and you plan to use this project.
Create a log project at the Log Service console.
Note: The region of the log project must be the same as that of the Kubernetes cluster.
Configure a machine group.
Note: Select Custom ID
and ensure that the value is the same as that of the environmental variable ALIYUN_LOGTAIL_USER_DEFINED_ID
in the Logtail DaemonSet YAML file edited in step 1.
Create a Logstore.
Note: You can reuse a created Logstore.
Configure the type of the configuration data to be collected.
Note: Ingress Controller logs are exported to Stdout, so select Standard Docker Output
.
Configure the source of the configuration data to be collected.
For more configuration items, read our documentation. The preceding information indicates that only the Stdout and Stderr logs containing "io.kubernetes.container.name": "nginx-ingress-controller"
will be collected.
Associate a machine group.
Check Ingress Controller request logs.
After external systems access the services in the Kubernetes cluster through Ingress, check the collected Ingress Controller request logs in the k8s-ingress-controller Logstore.
This section describes how to collect Ingress Controller logs to the self-built Elasticsearch (ES). Container Service also provides an appropriate solution if you want to collect and import Kubernetes cluster pod logs to the self-built ES. For more information, see A solution to log collection problems of Kubernetes clusters by using log-pilot, Elasticsearch, and Kibana.
Note: Skip this step if you have deployed them in the cluster.
For more information, see A solution to log collection problems of Kubernetes clusters by using log-pilot, Elasticsearch, and Kibana.
To collect Ingress Controller logs, add the following log collection configurations:
vim nginx-ingress-controller-log-patch.yaml
spec:
template:
spec:
containers:
- name: nginx-ingress-controller
env:
# ingress-controller is the index name.
- name: aliyun_logs_ingress-controller
value: "stdout"
# If you deploy nginx-ingress-controller by using Deployment:
kubectl -n kube-system patch deployment nginx-ingress-controller --patch "$(cat nginx-ingress-controller-log-patch.yaml)"
# If you deploy nginx-ingress-controller by using DaemonSet:
kubectl -n kube-system patch ds nginx-ingress-controller --patch "$(cat nginx-ingress-controller-log-patch.yaml)"
After external systems access the services in the Kubernetes cluster through Ingress, check the collected Ingress Controller request logs in Kibana.
To learn more about Alibaba Cloud Container Service for Kubernetes, visit https://www.alibabacloud.com/product/kubernetes
Deploying Multiple Ingress Controllers in a Kubernetes Cluster
166 posts | 30 followers
FollowDavidZhang - December 30, 2020
Alibaba Cloud Native - August 23, 2024
Alibaba Container Service - July 16, 2019
Alibaba Cloud Native - September 4, 2023
Alibaba Cloud Blockchain Service Team - January 17, 2019
Alibaba Cloud Native - February 15, 2023
166 posts | 30 followers
FollowRespond to sudden traffic spikes and minimize response time with Server Load Balancer
Learn MoreAlibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn MoreProvides a control plane to allow users to manage Kubernetes clusters that run based on different infrastructure resources
Learn MoreA secure image hosting platform providing containerized image lifecycle management
Learn MoreMore Posts by Alibaba Container Service