Kubernetes Assignment– 6
Security, Monitoring & Logging
Basic Questions
- Create a ServiceAccount named dev-user in the default namespace.
- Create a Role that allows listing Pods in the default namespace.
- Bind the Role to the dev-user ServiceAccount using a RoleBinding.
- Use kubectl auth can-i to check if dev-user can list Pods.
- Create a Role that allows creating ConfigMaps in a namespace.
- Create a ClusterRole that allows viewing nodes.
- Bind the ClusterRole to a ServiceAccount using a ClusterRoleBinding.
- Create a simple NetworkPolicy that denies all ingress traffic to Pods.
- Create a NetworkPolicy that only allows traffic from Pods with label role=frontend.
- Verify NetworkPolicy enforcement by testing Pod-to-Pod communication.
- Create a Secret with a username and password in base64 encoding.
- Mount the Secret into a Pod as environment variables.
- Enable encryption at rest for Secrets by editing the API server config.
- Deploy Prometheus using a Helm chart.
- Access the Prometheus UI inside the cluster.
- Deploy Grafana using a Helm chart.
- Add Prometheus as a data source in Grafana.
- Import a pre-built Kubernetes monitoring dashboard in Grafana.
- Deploy an Elasticsearch Pod using a Helm chart.
- Deploy Kibana and connect it to Elasticsearch.
Intermediate Questions
- Create a Role that allows viewing, creating, and deleting Pods in a namespace.
- Restrict a user to only use the dev namespace via RBAC.
- Create a RoleBinding for a specific user and verify access.
- Deny egress traffic for a Pod using a NetworkPolicy.
- Allow ingress traffic only on port 80 using a NetworkPolicy.
- Create a NetworkPolicy that allows Pods in the frontend namespace to access Pods in the backend namespace.
- Apply Pod Security Standards by enforcing restricted policy at the namespace level.
- Deploy a Pod as non-root and verify with kubectl exec.
- Add resource requests and limits to a Pod for security best practices.
- Create a Secret with TLS certificate and mount it into an Nginx Pod.
- Deploy Prometheus Operator for advanced monitoring.
- Configure Prometheus to scrape metrics from a custom app endpoint.
- Deploy Grafana with persistent storage enabled.
- Create a custom Grafana dashboard with CPU and memory metrics.
- Deploy Fluentd as a DaemonSet for log collection.
- Connect Fluentd to Elasticsearch and verify logs are ingested.
- Deploy Kibana and create an index pattern to view logs.
- Compare EFK vs ELK logging stack in a short write-up.
- Expose Grafana and Kibana using Ingress resources.
- Document security best practices for managing Kubernetes Secrets.
Advanced Questions
- Create an RBAC policy that restricts a ServiceAccount to only read Pods and ConfigMaps in a namespace.
- Assign the policy to a user and test with kubectl commands.
- Configure a NetworkPolicy that allows only Pods labeled app=api to talk to app=db Pods on port 3306.
- Deploy a Pod with PodSecurityContext to run as non-root, with read-only filesystem.
- Enable Secrets encryption at rest and validate by inspecting the etcd database.
- Deploy Prometheus and Grafana using a single Helm chart (kube-prometheus-stack).
- Create Grafana alerts for high Pod CPU usage.
- Integrate Prometheus alerts with Slack or Email.
- Deploy an EFK stack (Elasticsearch, Fluentd, Kibana) with persistent storage.
- Deliver a final hands-on project:
- Create namespace secure-app
- Deploy an app Pod with restricted PodSecurityContext
- Use RBAC to give read-only access to secure-app namespace
- Apply NetworkPolicy to restrict traffic to the app
- Deploy Prometheus + Grafana to monitor the app
- Deploy EFK stack to collect and visualize app logs.