Skip to contentমূল লেখায় যান

Topic 13 · DevOps & Cloudটপিক 13 · DevOps & Cloud

Kubernetes Security and Troubleshooting

This page is about two jobs on a Kubernetes cluster: keeping it safe (Secrets, who may do what, which Pods may run, which Pods may talk to which) and finding out why a Pod fails, with a practice run on the local cluster of Kubernetes Basics.

27 min read27 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 29 sources29টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Who may do what, and what Secrets hideকে কী করতে পারে, আর Secret কী লুকায়

Ask “can this identity do this?” and see that base64 is not encryption.জিজ্ঞেস করুন “এই identity কি এটা করতে পারে?” আর দেখুন base64 মানে এনক্রিপশন নয়।

2 min2 মিনিট8 steps8টি ধাপ
  • Rules matchingমিলে যাওয়া নিয়ম1
  • can-i answercan-i উত্তরyes
pod-readerpod-readerRoleRoletestertesteraccountঅ্যাকাউন্টsec-labsec-labnamespaceনেমস্পেসdefaultdefaultnamespaceনেমস্পেসsec-lab: get list watch podssec-lab: get list watch podsservice accountসার্ভিস অ্যাকাউন্ট

You’ll learnআপনি শিখবেন

  • A Role sets permissions in one namespaceRole একটা namespace-এ অনুমতি দেয়✓
  • A RoleBinding gives a Role to a subjectRoleBinding একটা Role কোনো subject-কে দেয়
  • No matching rule means no: there are no deny rulesনিয়ম না মিললে no: deny নিয়ম নেই
  • base64 is encoding, not encryptionbase64 এনকোডিং, এনক্রিপশন নয়
  • Without the k8s:enc prefix, etcd holds clear textk8s:enc prefix না থাকলে etcd-তে খোলা লেখা থাকে

What it is

Secrets. A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key Source 1সোর্স 1. Kubernetes Secrets are, by default, stored unencrypted in the API server's underlying data store (etcd) Source 1সোর্স 1. Anyone with API access can retrieve or modify a Secret, and so can anyone with access to etcd Source 1সোর্স 1.

Who may do what. Role-based access control (RBAC) is a method of regulating access to computer or network resources based on the roles of individual users within your organization Source 5সোর্স 5. A service account is a type of non-human account that, in Kubernetes, provides a distinct identity in a Kubernetes cluster Source 6সোর্স 6.

Which Pods may run. The Pod Security Standards define three different policies to broadly cover the security spectrum Source 10সোর্স 10, and Kubernetes offers a built-in Pod Security admission controller to enforce the Pod Security Standards Source 11সোর্স 11.

Which Pods may talk to which. If you want to control traffic flow at the IP address or port level for TCP, UDP, and SCTP protocols, then you might consider using Kubernetes NetworkPolicies for particular applications in your cluster Source 13সোর্স 13.

Why a Pod fails. The first step in debugging a Pod is taking a look at it Source 15সোর্স 15. Ephemeral containers are useful for interactive troubleshooting when kubectl exec is insufficient because a container has crashed or a container image doesn't include debugging utilities, such as with distroless images Source 16সোর্স 16.

সহজ English

Secrets. A Secret is an object that holds a small amount of sensitive data, such as a password, a token, or a key Source 1সোর্স 1. By default, Kubernetes stores Secrets without encryption, in the data store (etcd) that the API server uses underneath Source 1সোর্স 1. Anyone with access to the API can read or change a Secret, and so can anyone with access to etcd Source 1সোর্স 1.

Who may do what. Role-based access control (RBAC) is a way to regulate access to computer or network resources based on the roles of the individual users in your organization Source 5সোর্স 5. A service account is a non-human account; in Kubernetes it provides a distinct identity in the cluster Source 6সোর্স 6.

Which Pods may run. The Pod Security Standards define three policies that broadly cover the security spectrum Source 10সোর্স 10, and Kubernetes has a built-in Pod Security admission controller to enforce them Source 11সোর্স 11.

Which Pods may talk to which. To control traffic at the IP address or port level for TCP, UDP, and SCTP, you might use Kubernetes NetworkPolicies for particular applications in your cluster Source 13সোর্স 13.

Why a Pod fails. The first step in debugging a Pod is to take a look at it Source 15সোর্স 15. Ephemeral containers help with interactive troubleshooting when kubectl exec is not enough, because a container has crashed or its image has no debugging tools, as with distroless images Source 16সোর্স 16.

বাংলা ব্যাখ্যা

Secret। Secret হলো একটা object, যাতে password, token বা key-এর মতো অল্প পরিমাণ sensitive data থাকে Source 1সোর্স 1। ডিফল্টভাবে Kubernetes Secret-কে encrypt না করেই রাখে, API server নিচে যে data store (etcd) ব্যবহার করে সেখানে Source 1সোর্স 1। API access আছে এমন যে কেউ একটা Secret পড়তে বা বদলাতে পারে, আর etcd-তে access আছে এমন যে কেউও পারে Source 1সোর্স 1।

কে কী করতে পারে। Role-based access control (RBAC) হলো প্রতিষ্ঠানের আলাদা আলাদা user-এর role-এর ভিত্তিতে computer বা network resource-এ access নিয়ন্ত্রণের একটা পদ্ধতি Source 5সোর্স 5। service account হলো একটা non-human account; Kubernetes-এ এটা cluster-এ একটা স্বতন্ত্র পরিচয় দেয় Source 6সোর্স 6।

কোন Pod চলতে পারবে। Pod Security Standards নিরাপত্তার পরিসর মোটামুটি ঢেকে দেওয়ার জন্য তিনটা আলাদা policy ঠিক করে Source 10সোর্স 10, আর সেগুলো প্রয়োগ করার জন্য Kubernetes-এ built-in Pod Security admission controller আছে Source 11সোর্স 11।

কোন Pod কার সাথে কথা বলবে। TCP, UDP আর SCTP protocol-এ IP address বা port level-এ traffic নিয়ন্ত্রণ করতে চাইলে cluster-এর নির্দিষ্ট application-এর জন্য Kubernetes NetworkPolicy ব্যবহার করার কথা ভাবতে পারেন Source 13সোর্স 13।

Pod কেন ব্যর্থ হয়। একটা Pod debug করার প্রথম ধাপ হলো সেটা ভালো করে দেখা Source 15সোর্স 15। kubectl exec যথেষ্ট না হলে ephemeral container interactive troubleshooting-এ কাজে লাগে, কারণ একটা container crash করেছে অথবা container image-এ debugging utility নেই, যেমন distroless image-এ Source 16সোর্স 16।

How it works

Secrets are encoded, not encrypted. The values for all keys in the data field of a Secret have to be base64-encoded strings Source 1সোর্স 1. A comment in the TLS example of the Secrets page says that base64 encoded values are obscured, but that this does NOT provide any useful level of confidentiality Source 1সোর্স 1. By default, the API server stores plain-text representations of resources into etcd, with no at-rest encryption Source 3সোর্স 3; if you are running the kube-apiserver without the --encryption-provider-config command line argument, you do not have encryption at rest enabled Source 3সোর্স 3. To check this, you can use the etcdctl command line program to retrieve the contents of your secret data Source 3সোর্স 3:

ETCDCTL_API=3 etcdctl get /registry/secrets/default/secret1 [...] | hexdump -C

Here [...] must be the additional arguments for connecting to the etcd server Source 3সোর্স 3. In the docs' check of an aescbc setup, the stored Secret has to be prefixed with k8s:enc:aescbc:v1:, which indicates the aescbc provider has encrypted the resulting data Source 3সোর্স 3.

How a Pod gets a Secret, and who can read it. Secrets can be mounted as data volumes or exposed as environment variables to be used by a container in a Pod Source 1সোর্স 1. To use a Secret in an environment variable, you add an environment variable for each Secret key that you want to use to the env[].valueFrom.secretKeyRef field Source 1সোর্স 1. Anyone who is authorized to create a Pod in a namespace can use that access to read any Secret in that namespace; this includes indirect access such as the ability to create a Deployment Source 1সোর্স 1. Two of the good practices for Secrets: for humans, restrict get, watch, or list access to Secrets Source 2সোর্স 2, and note that granting list access to Secrets implicitly lets the subject fetch the contents of the Secrets Source 2সোর্স 2; and avoid sharing Secret manifests, because sharing the file or checking it in to a source repository means the secret is available to everyone who can read the manifest Source 2সোর্স 2.

Roles, bindings, and service accounts. An RBAC Role or ClusterRole contains rules that represent a set of permissions Source 5সোর্স 5. Permissions are purely additive (there are no "deny" rules) Source 5সোর্স 5. A Role always sets permissions within a particular namespace; when you create a Role, you have to specify the namespace it belongs in Source 5সোর্স 5. ClusterRole, by contrast, is a non-namespaced resource Source 5সোর্স 5. A role binding grants the permissions defined in a role to a user or set of users; it holds a list of subjects (users, groups, or service accounts), and a reference to the role being granted Source 5সোর্স 5. A RoleBinding grants permissions within a specific namespace whereas a ClusterRoleBinding grants that access cluster-wide Source 5সোর্স 5. Every namespace gets a default ServiceAccount upon creation Source 6সোর্স 6. If you deploy a Pod in a namespace, and you don't manually assign a ServiceAccount to the Pod, Kubernetes assigns the default ServiceAccount for that namespace to the Pod Source 6সোর্স 6.

These commands create the pieces and ask the API what an identity may do Source 7সোর্স 7 Source 8সোর্স 8 Source 9সোর্স 9:

CommandWhat it does
kubectl create role pod-reader --verb=get --verb=list --verb=watch --resource=podsCreates a role with a single rule
kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname]Creates a role binding for a particular role or cluster role; a service account is given in the format <namespace>:<name>
kubectl auth can-i list pods --as=system:serviceaccount:dev:foo -n prodChecks whether an action is allowed, as another identity: --as is the username to impersonate for the operation, a regular user or a service account in a namespace

Which Pods may run: Pod Security. The Pod Security Standards define three different policies; these policies are cumulative and range from highly-permissive to highly-restrictive Source 10সোর্স 10:

ProfileDescription
PrivilegedUnrestricted policy, providing the widest possible level of permissions
BaselineMinimally restrictive policy which prevents known privilege escalations
RestrictedHeavily restricted policy, following current Pod hardening best practices

Kubernetes defines a set of labels that you can set to define which of the predefined Pod Security Standard levels you want to use for a namespace Source 11সোর্স 11. The label you select defines what action the control plane takes if a potential violation is detected Source 11সোর্স 11:

ModeWhat a violation does
enforcePolicy violations will cause the pod to be rejected
auditPolicy violations will trigger the addition of an audit annotation to the event recorded in the audit log, but are otherwise allowed
warnPolicy violations will trigger a user-facing warning, but are otherwise allowed

The label has the form pod-security.kubernetes.io/<MODE>: <LEVEL>, where MODE must be one of enforce, audit, or warn, and LEVEL must be one of privileged, baseline, or restricted Source 11সোর্স 11. Enforce mode is not applied to workload resources, only to the resulting pod objects Source 11সোর্স 11. The docs add the labels pod-security.kubernetes.io/enforce=restricted and pod-security.kubernetes.io/enforce-version=v1.37 to an existing namespace with kubectl label --overwrite ns my-existing-namespace, which adds the enforce=restricted policy and pins the restricted policy version to v1.37 Source 12সোর্স 12. These are the four controls of the Restricted policy that step 3 of the tutorial's run meets Source 10সোর্স 10:

ControlWhat the Restricted policy saysField
Privilege escalationAllowed value falsesecurityContext.allowPrivilegeEscalation
CapabilitiesContainers must drop ALL capabilities, and are only permitted to add back the NET_BIND_SERVICE capabilitysecurityContext.capabilities.drop
Running as non-rootContainers must be required to run as non-root users; allowed value truesecurityContext.runAsNonRoot
SeccompThe profile must be explicitly set to one of the allowed values, RuntimeDefault or Localhost; both the Unconfined profile and the absence of a profile are prohibitedsecurityContext.seccompProfile.type

Which Pods may talk to which: NetworkPolicy. Network policies are implemented by the network plugin Source 13সোর্স 13. Creating a NetworkPolicy resource without a controller that implements it will have no effect Source 13সোর্স 13. By default, a pod is non-isolated for ingress; all inbound connections are allowed Source 13সোর্স 13. A pod is isolated for ingress if there is any NetworkPolicy that both selects the pod and has "Ingress" in its policyTypes Source 13সোর্স 13. When a pod is isolated for ingress, the only allowed connections into the pod are those from the pod's node and those allowed by the ingress list of some NetworkPolicy that applies to the pod for ingress Source 13সোর্স 13. Network policies do not conflict; they are additive Source 13সোর্স 13. An empty podSelector selects all pods in the namespace Source 13সোর্স 13, so a NetworkPolicy that selects all pods but does not allow any ingress traffic to those pods makes a default ingress isolation Source 13সোর্স 13. In an ingress rule, a podSelector under from selects particular Pods in the same namespace as the NetworkPolicy which should be allowed as ingress sources Source 13সোর্স 13. A default deny-all egress policy also blocks DNS traffic Source 13সোর্স 13. kind ships with a simple networking implementation (“kindnetd”) based around standard CNI plugins, and you may disable the default to install a different CNI Source 14সোর্স 14; network policies are implemented by the network plugin Source 13সোর্স 13.

Why a Pod fails: the order of the checks. kubectl get pods lists all pods in the namespace Source 27সোর্স 27. When a pod is failing to start repeatedly, CrashLoopBackOff may appear in the Status field of some kubectl commands Source 17সোর্স 17, and the docs show such a listing with the columns READY, STATUS, and RESTARTS Source 17সোর্স 17. To check the current state of the Pod and recent events, run kubectl describe pods ${POD_NAME} Source 15সোর্স 15; once your pod has been scheduled, the methods described in Debug Running Pods are available Source 15সোর্স 15. After containers in a Pod exit, the kubelet restarts them with an exponential backoff delay (10s, 20s, 40s, …), that is capped at 300 seconds (5 minutes) Source 17সোর্স 17; once a container has executed for 10 minutes without any problems, the kubelet resets the restart backoff timer for that container Source 17সোর্স 17. CrashLoopBackOff state indicates that the backoff delay mechanism is currently in effect for a given container that is in a crash loop, failing and restarting repeatedly Source 17সোর্স 17. To investigate it, check the logs with kubectl logs <name-of-pod>, and inspect the events with kubectl describe pod <name-of-pod> Source 17সোর্স 17. kubectl logs prints the logs for a container in a pod or specified resource, and -p, --previous prints the logs for the previous instance of the container in a pod if it exists Source 18সোর্স 18. kubectl exec my-pod -- ls / runs a command in an existing pod Source 27সোর্স 27. kubectl debug can add an ephemeral container to an already running pod, for example to add debugging utilities without restarting the pod Source 19সোর্স 19; its --target flag names the container whose processes to target Source 19সোর্স 19, and the --target parameter targets the process namespace of another container, and must be supported by the container runtime Source 16সোর্স 16. If you run kubectl debug to add an ephemeral container without the required permission, you will see an error similar to Error from server (Forbidden) Source 16সোর্স 16. This diagram is the tutorial's own list of those commands, in the order of the tutorial's run:

Pod not working? Go down the list until you know why.

kubectl get pod            STATUS, RESTARTS            crashing? ready?
kubectl describe pod       Events                      scheduled, pulled, started, backed off
kubectl logs --previous    logs of the last run        what the container printed before it exited
kubectl exec               a command inside it         needs a shell in the image
kubectl debug              a new container beside it   for an image with no shell

সহজ English

Secrets are encoded, not encrypted. The values for all keys in the data field of a Secret have to be base64-encoded strings Source 1সোর্স 1. A comment in the TLS example of the Secrets page says that base64 encoding obscures the values, but does NOT provide any useful level of confidentiality Source 1সোর্স 1. By default, the API server stores resources in etcd as plain text, with no at-rest encryption Source 3সোর্স 3; if you run the kube-apiserver without the --encryption-provider-config command line argument, encryption at rest is not enabled Source 3সোর্স 3. To check, you can use the etcdctl command line program to read your secret data Source 3সোর্স 3:

ETCDCTL_API=3 etcdctl get /registry/secrets/default/secret1 [...] | hexdump -C

Here [...] stands for the extra arguments that are needed to connect to the etcd server Source 3সোর্স 3. In the docs' check of an aescbc setup, the stored Secret has to start with k8s:enc:aescbc:v1:, which shows that the aescbc provider has encrypted the data Source 3সোর্স 3.

How a Pod gets a Secret, and who can read it. Secrets can be mounted as data volumes or exposed as environment variables for a container in a Pod Source 1সোর্স 1. To use a Secret in an environment variable, you add an environment variable for each Secret key that you want to use to the env[].valueFrom.secretKeyRef field Source 1সোর্স 1. Anyone who is allowed to create a Pod in a namespace can use that access to read any Secret in that namespace, including indirect access such as the ability to create a Deployment Source 1সোর্স 1. Two of the good practices for Secrets: for humans, restrict get, watch, or list access to Secrets Source 2সোর্স 2, and note that granting list access to Secrets implicitly lets the subject fetch the contents of the Secrets Source 2সোর্স 2; and avoid sharing Secret manifests, because sharing the file or checking it in to a source repository means that everyone who can read the manifest has the secret Source 2সোর্স 2.

Roles, bindings, and service accounts. An RBAC Role or ClusterRole contains rules that make up a set of permissions Source 5সোর্স 5. Permissions are purely additive (there are no "deny" rules) Source 5সোর্স 5. A Role always sets permissions within one namespace, and you have to name that namespace when you create the Role Source 5সোর্স 5. A ClusterRole, by contrast, is not tied to a namespace Source 5সোর্স 5. A role binding grants the permissions of a role to a user or a set of users; it holds a list of subjects (users, groups, or service accounts), and a reference to the role being granted Source 5সোর্স 5. A RoleBinding grants permissions within one namespace, whereas a ClusterRoleBinding grants that access cluster-wide Source 5সোর্স 5. Every namespace gets a default ServiceAccount when it is created Source 6সোর্স 6. If you deploy a Pod in a namespace and you do not assign a ServiceAccount to the Pod yourself, Kubernetes assigns the default ServiceAccount of that namespace to the Pod Source 6সোর্স 6.

These commands create the pieces and ask the API what an identity may do Source 7সোর্স 7 Source 8সোর্স 8 Source 9সোর্স 9:

CommandWhat it does
kubectl create role pod-reader --verb=get --verb=list --verb=watch --resource=podsCreates a role with a single rule
kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname]Creates a role binding for a particular role or cluster role; a service account is written as <namespace>:<name>
kubectl auth can-i list pods --as=system:serviceaccount:dev:foo -n prodChecks whether an action is allowed, as another identity: --as is the user name to impersonate, a regular user or a service account in a namespace

Which Pods may run: Pod Security. The Pod Security Standards define three policies; they are cumulative and range from highly permissive to highly restrictive Source 10সোর্স 10:

ProfileDescription
PrivilegedUnrestricted policy, with the widest possible level of permissions
BaselineMinimally restrictive policy that prevents known privilege escalations
RestrictedHeavily restricted policy that follows current Pod hardening best practices

Kubernetes defines labels that you can set to choose which of the predefined Pod Security Standard levels a namespace uses Source 11সোর্স 11. The label that you choose decides what the control plane does when it detects a possible violation Source 11সোর্স 11:

ModeWhat a violation does
enforceA policy violation causes the pod to be rejected
auditA policy violation adds an audit annotation to the event recorded in the audit log, but is otherwise allowed
warnA policy violation triggers a warning for the user, but is otherwise allowed

The label looks like pod-security.kubernetes.io/<MODE>: <LEVEL>, where MODE is one of enforce, audit, or warn, and LEVEL is one of privileged, baseline, or restricted Source 11সোর্স 11. Enforce mode is applied only to the resulting pod objects, not to workload resources Source 11সোর্স 11. The docs add the labels pod-security.kubernetes.io/enforce=restricted and pod-security.kubernetes.io/enforce-version=v1.37 to an existing namespace with kubectl label --overwrite ns my-existing-namespace, which adds the enforce=restricted policy and pins the restricted policy version to v1.37 Source 12সোর্স 12. These are the four controls of the Restricted policy that step 3 of the tutorial's run meets Source 10সোর্স 10:

ControlWhat the Restricted policy saysField
Privilege escalationAllowed value falsesecurityContext.allowPrivilegeEscalation
CapabilitiesContainers must drop ALL capabilities, and may only add back the NET_BIND_SERVICE capabilitysecurityContext.capabilities.drop
Running as non-rootContainers must be required to run as non-root users; allowed value truesecurityContext.runAsNonRoot
SeccompThe profile must be set explicitly to an allowed value, RuntimeDefault or Localhost; both the Unconfined profile and no profile at all are prohibitedsecurityContext.seccompProfile.type

Which Pods may talk to which: NetworkPolicy. Network policies are implemented by the network plugin Source 13সোর্স 13. A NetworkPolicy resource created without a controller that implements it has no effect Source 13সোর্স 13. By default, a pod is non-isolated for ingress: all inbound connections are allowed Source 13সোর্স 13. A pod is isolated for ingress if some NetworkPolicy both selects the pod and has "Ingress" in its policyTypes Source 13সোর্স 13. When a pod is isolated for ingress, the only connections allowed into it are those from the pod's node and those allowed by the ingress list of some NetworkPolicy that applies to the pod for ingress Source 13সোর্স 13. Network policies do not conflict; they are additive Source 13সোর্স 13. An empty podSelector selects all pods in the namespace Source 13সোর্স 13, so a NetworkPolicy that selects all pods but allows no ingress traffic to them makes a default ingress isolation Source 13সোর্স 13. In an ingress rule, a podSelector under from selects particular Pods in the same namespace as the NetworkPolicy that should be allowed as ingress sources Source 13সোর্স 13. A default deny-all egress policy also blocks DNS traffic Source 13সোর্স 13. kind ships with a simple networking implementation (“kindnetd”) based on standard CNI plugins, and you may disable the default to install a different CNI Source 14সোর্স 14; network policies are implemented by the network plugin Source 13সোর্স 13.

Why a Pod fails: the order of the checks. kubectl get pods lists all the pods in the namespace Source 27সোর্স 27. When a pod is failing to start repeatedly, CrashLoopBackOff may appear in the Status field of some kubectl commands Source 17সোর্স 17, and the docs show such a listing with the columns READY, STATUS, and RESTARTS Source 17সোর্স 17. To see the current state of the Pod and its recent events, run kubectl describe pods ${POD_NAME} Source 15সোর্স 15; once your pod has been scheduled, the methods in Debug Running Pods are available Source 15সোর্স 15. After containers in a Pod exit, the kubelet restarts them with an exponential backoff delay (10s, 20s, 40s, …) that is capped at 300 seconds (5 minutes) Source 17সোর্স 17; once a container has run for 10 minutes without any problems, the kubelet resets the restart backoff timer for that container Source 17সোর্স 17. CrashLoopBackOff means that the backoff delay mechanism is in effect for a container that is in a crash loop, failing and restarting repeatedly Source 17সোর্স 17. To investigate it, check the logs with kubectl logs <name-of-pod>, and inspect the events with kubectl describe pod <name-of-pod> Source 17সোর্স 17. kubectl logs prints the logs for a container in a pod or specified resource, and -p, --previous prints the logs for the previous instance of the container in a pod if it exists Source 18সোর্স 18. kubectl exec my-pod -- ls / runs a command in an existing pod Source 27সোর্স 27. kubectl debug can add an ephemeral container to an already running pod, for example to add debugging utilities without restarting the pod Source 19সোর্স 19; its --target flag names the container whose processes to target Source 19সোর্স 19, and the --target parameter targets the process namespace of another container, and must be supported by the container runtime Source 16সোর্স 16. If you run kubectl debug to add an ephemeral container without the required permission, you will see an error similar to Error from server (Forbidden) Source 16সোর্স 16. This diagram is the tutorial's own list of those commands, in the order of the tutorial's run:

Pod not working? Go down the list until you know why.

kubectl get pod            STATUS, RESTARTS            crashing? ready?
kubectl describe pod       Events                      scheduled, pulled, started, backed off
kubectl logs --previous    logs of the last run        what the container printed before it exited
kubectl exec               a command inside it         needs a shell in the image
kubectl debug              a new container beside it   for an image with no shell

বাংলা ব্যাখ্যা

Secret encoded, encrypted নয়। একটা Secret-এর data field-এর সব key-এর মান base64-encoded string হতে হয় Source 1সোর্স 1। Secrets পাতার TLS উদাহরণের একটা comment বলে, base64 encoding মানগুলো obscure করে, কিন্তু তাতে কোনো কার্যকর মাত্রার confidentiality পাওয়া যায় না Source 1সোর্স 1। ডিফল্টভাবে API server resource-গুলো plain text হিসেবে etcd-তে রাখে, at-rest encryption ছাড়া Source 3সোর্স 3; kube-apiserver --encryption-provider-config command line argument ছাড়া চালালে encryption at rest চালু থাকে না Source 3সোর্স 3। এটা যাচাই করতে etcdctl command line program দিয়ে আপনার secret data পড়তে পারেন Source 3সোর্স 3:

ETCDCTL_API=3 etcdctl get /registry/secrets/default/secret1 [...] | hexdump -C

এখানে [...] হলো etcd server-এর সাথে সংযোগের জন্য দরকারি বাড়তি argument Source 3সোর্স 3। aescbc setup-এর docs-এর check-এ stored Secret-এর শুরুতে k8s:enc:aescbc:v1: থাকতে হয়, যা দেখায় aescbc provider data encrypt করেছে Source 3সোর্স 3।

Pod কীভাবে Secret পায়, আর কে পড়তে পারে। Secret data volume হিসেবে mount করা যায়, অথবা Pod-এর একটা container-এর জন্য environment variable হিসেবে দেওয়া যায় Source 1সোর্স 1। একটা Secret environment variable-এ ব্যবহার করতে আপনি যে Secret key ব্যবহার করতে চান, তার জন্য env[].valueFrom.secretKeyRef field-এ একটা environment variable যোগ করেন Source 1সোর্স 1। একটা namespace-এ Pod তৈরির অনুমতি আছে এমন যে কেউ সেই access দিয়ে ওই namespace-এর যেকোনো Secret পড়তে পারে, এর মধ্যে আছে পরোক্ষ access, যেমন Deployment তৈরির ক্ষমতা Source 1সোর্স 1। Secret-এর কয়েকটা good practice: মানুষের জন্য Secret-এ get, watch বা list access সীমিত করুন Source 2সোর্স 2, আর মনে রাখুন Secret-এ list access দিলে access-প্রাপক পরোক্ষভাবে Secret-গুলোর বিষয়বস্তু আনতে পারে Source 2সোর্স 2; আর Secret manifest শেয়ার করা এড়িয়ে চলুন, কারণ ফাইলটা শেয়ার করলে বা source repository-তে check in করলে manifest যে কেউ পড়তে পারে, সে-ই secret পেয়ে যায় Source 2সোর্স 2।

Role, binding আর service account। একটা RBAC Role বা ClusterRole-এ এমন rule থাকে, যা একটা permission-এর সেট বোঝায় Source 5সোর্স 5। Permission সম্পূর্ণ যোগাত্মক ("deny" rule বলে কিছু নেই) Source 5সোর্স 5। একটা Role সবসময় একটা নির্দিষ্ট namespace-এর ভেতরে permission ঠিক করে; Role তৈরির সময় কোন namespace-এ সেটা থাকবে, তা বলে দিতে হয় Source 5সোর্স 5। ClusterRole তার বিপরীতে namespace-এর সাথে বাঁধা নয় Source 5সোর্স 5। একটা role binding একটা role-এর permission একজন user বা একদল user-কে দেয়; এতে subject-এর (user, group বা service account) একটা তালিকা আর যে role দেওয়া হচ্ছে তার একটা reference থাকে Source 5সোর্স 5। RoleBinding একটা নির্দিষ্ট namespace-এর ভেতরে permission দেয়, আর ClusterRoleBinding সেই access দেয় cluster জুড়ে Source 5সোর্স 5। প্রতিটা namespace তৈরির সময় একটা default ServiceAccount পায় Source 6সোর্স 6। একটা namespace-এ Pod deploy করে আপনি নিজে Pod-কে কোনো ServiceAccount না দিলে Kubernetes সেই namespace-এর default ServiceAccount Pod-কে দেয় Source 6সোর্স 6।

এই command-গুলো টুকরোগুলো তৈরি করে আর API-কে জিজ্ঞেস করে একটা identity কী করতে পারে Source 7সোর্স 7 Source 8সোর্স 8 Source 9সোর্স 9:

Commandকী করে
kubectl create role pod-reader --verb=get --verb=list --verb=watch --resource=podsএকটা মাত্র rule-সহ role তৈরি করে
kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serviceaccount=namespace:serviceaccountname]একটা নির্দিষ্ট role বা cluster role-এর জন্য role binding তৈরি করে; service account লেখা হয় <namespace>:<name> format-এ
kubectl auth can-i list pods --as=system:serviceaccount:dev:foo -n prodএকটা action অনুমোদিত কি না যাচাই করে, অন্য একটা identity হিসেবে: --as হলো operation-এর জন্য impersonate করার username, একজন সাধারণ user বা একটা namespace-এর service account

কোন Pod চলতে পারবে: Pod Security। Pod Security Standards তিনটা আলাদা policy ঠিক করে; এগুলো ক্রমযোজ্য (cumulative) আর অত্যন্ত শিথিল থেকে অত্যন্ত কঠোর পর্যন্ত বিস্তৃত Source 10সোর্স 10:

Profileবিবরণ
Privilegedবাধাহীন policy, সম্ভাব্য সবচেয়ে বিস্তৃত permission-সহ
Baselineন্যূনতম বাধা দেওয়া policy, যা পরিচিত privilege escalation আটকায়
Restrictedঅত্যন্ত কঠোর policy, যা বর্তমান Pod hardening-এর best practice মেনে চলে

Kubernetes এমন কিছু label ঠিক করে, যা দিয়ে আপনি একটা namespace-এর জন্য আগে থেকে ঠিক করা Pod Security Standard level-এর কোনটা ব্যবহার করবেন, তা বেছে নিতে পারেন Source 11সোর্স 11। আপনি যে label বেছে নেন, সেটা ঠিক করে সম্ভাব্য violation ধরা পড়লে control plane কী করবে Source 11সোর্স 11:

Modeviolation হলে কী হয়
enforcepolicy violation হলে pod reject হয়
auditpolicy violation হলে audit log-এ রেকর্ড করা event-এ একটা audit annotation যোগ হয়, তবে অন্যথায় তা অনুমোদিত
warnpolicy violation হলে user-কে একটা warning দেখানো হয়, তবে অন্যথায় তা অনুমোদিত

label-এর রূপ pod-security.kubernetes.io/<MODE>: <LEVEL>, যেখানে MODE হলো enforce, audit বা warn-এর একটা, আর LEVEL হলো privileged, baseline বা restricted-এর একটা Source 11সোর্স 11। Enforce mode শুধু ফলস্বরূপ pod object-এ প্রয়োগ হয়, workload resource-এ নয় Source 11সোর্স 11। docs একটা বিদ্যমান namespace-এ pod-security.kubernetes.io/enforce=restricted আর pod-security.kubernetes.io/enforce-version=v1.37 label যোগ করে kubectl label --overwrite ns my-existing-namespace দিয়ে, যা enforce=restricted policy যোগ করে আর restricted policy version v1.37-এ বেঁধে দেয় Source 12সোর্স 12। টিউটোরিয়ালের run-এর ধাপ ৩ Restricted policy-র যে চারটা control পূরণ করে, সেগুলো এই Source 10সোর্স 10:

ControlRestricted policy কী বলেField
Privilege escalationঅনুমোদিত মান falsesecurityContext.allowPrivilegeEscalation
CapabilitiesContainer-কে সব capability drop করতে হবে, আর শুধু NET_BIND_SERVICE capability ফিরিয়ে যোগ করার অনুমতি আছেsecurityContext.capabilities.drop
Running as non-rootContainer-কে non-root user হিসেবে চালানো বাধ্যতামূলক করতে হবে; অনুমোদিত মান truesecurityContext.runAsNonRoot
Seccompprofile স্পষ্টভাবে অনুমোদিত মানগুলোর একটায় (RuntimeDefault বা Localhost) ঠিক করতে হবে; Unconfined profile আর profile না থাকা, দুটোই নিষিদ্ধsecurityContext.seccompProfile.type

কোন Pod কার সাথে কথা বলবে: NetworkPolicy। Network policy প্রয়োগ করে network plugin Source 13সোর্স 13। যে controller NetworkPolicy প্রয়োগ করে, সেটা ছাড়া একটা NetworkPolicy resource তৈরি করলে তার কোনো প্রভাব পড়ে না Source 13সোর্স 13। ডিফল্টভাবে একটা pod ingress-এর জন্য non-isolated; সব inbound connection অনুমোদিত Source 13সোর্স 13। কোনো NetworkPolicy যদি pod-টাকে select করে আর তার policyTypes-এ "Ingress" থাকে, তাহলে pod-টা ingress-এর জন্য isolated Source 13সোর্স 13। একটা pod ingress-এর জন্য isolated হলে তার ভেতরে শুধু সেই connection-গুলো অনুমোদিত, যেগুলো pod-এর node থেকে আসে আর যেগুলো সেই pod-এ ingress-এর জন্য প্রযোজ্য কোনো NetworkPolicy-র ingress list অনুমতি দেয় Source 13সোর্স 13। Network policy-গুলো সংঘর্ষ করে না; সেগুলো যোগাত্মক Source 13সোর্স 13। খালি podSelector namespace-এর সব pod select করে Source 13সোর্স 13, তাই যে NetworkPolicy সব pod select করে কিন্তু সেগুলোতে কোনো ingress traffic অনুমতি দেয় না, সেটা একটা default ingress isolation বানায় Source 13সোর্স 13। একটা ingress rule-এর from-এর নিচে podSelector NetworkPolicy-র একই namespace-এর সেই নির্দিষ্ট Pod-গুলো select করে, যাদের ingress source হিসেবে অনুমতি দেওয়া উচিত Source 13সোর্স 13। একটা default deny-all egress policy DNS traffic-ও আটকায় Source 13সোর্স 13। kind একটা সরল networking implementation (“kindnetd”) নিয়ে আসে, যা standard CNI plugin-এর ওপর দাঁড়িয়ে, আর আপনি ডিফল্টটা বন্ধ করে অন্য একটা CNI install করতে পারেন Source 14সোর্স 14; network policy প্রয়োগ করে network plugin Source 13সোর্স 13।

Pod কেন ব্যর্থ হয়: check-এর ক্রম। kubectl get pods namespace-এর সব pod তালিকাভুক্ত করে Source 27সোর্স 27। একটা pod বারবার চালু হতে ব্যর্থ হলে কিছু kubectl command-এর Status field-এ CrashLoopBackOff দেখা যেতে পারে Source 17সোর্স 17, আর docs READY, STATUS ও RESTARTS column-সহ এমন একটা তালিকা দেখায় Source 17সোর্স 17। Pod-এর বর্তমান state আর সাম্প্রতিক event দেখতে kubectl describe pods ${POD_NAME} চালান Source 15সোর্স 15; আপনার pod schedule হয়ে গেলে Debug Running Pods-এর পদ্ধতিগুলো পাওয়া যায় Source 15সোর্স 15। একটা Pod-এর container exit করার পরে kubelet সেগুলো exponential backoff delay (10s, 20s, 40s, …) দিয়ে restart করে, যা 300 সেকেন্ডে (5 মিনিট) সীমিত Source 17সোর্স 17; একটা container কোনো সমস্যা ছাড়া 10 মিনিট চললে kubelet সেই container-এর restart backoff timer reset করে Source 17সোর্স 17। CrashLoopBackOff মানে crash loop-এ থাকা, বারবার ব্যর্থ হয়ে restart হওয়া একটা container-এর জন্য backoff delay mechanism এখন কার্যকর Source 17সোর্স 17। এটা তদন্ত করতে kubectl logs <name-of-pod> দিয়ে log দেখুন, আর kubectl describe pod <name-of-pod> দিয়ে event পরীক্ষা করুন Source 17সোর্স 17। kubectl logs একটা pod বা নির্দিষ্ট resource-এর container-এর log দেখায়, আর -p, --previous pod-এর container-এর আগের instance-এর log দেখায়, যদি থাকে Source 18সোর্স 18। kubectl exec my-pod -- ls / একটা বিদ্যমান pod-এ command চালায় Source 27সোর্স 27। kubectl debug একটা চলমান pod-এ ephemeral container যোগ করতে পারে, যেমন pod restart না করেই debugging utility যোগ করতে Source 19সোর্স 19; তার --target flag বলে কোন container-এর process-গুলোকে target করা হবে Source 19সোর্স 19, আর --target parameter অন্য একটা container-এর process namespace target করে, আর container runtime-কে সেটা support করতে হয় Source 16সোর্স 16। প্রয়োজনীয় permission ছাড়া kubectl debug দিয়ে ephemeral container যোগ করতে গেলে আপনি Error from server (Forbidden)-এর মতো একটা error দেখবেন Source 16সোর্স 16। এই diagram সেই command-গুলোর টিউটোরিয়ালের নিজের তালিকা, টিউটোরিয়ালের run-এর ক্রমে:

Pod not working? Go down the list until you know why.

kubectl get pod            STATUS, RESTARTS            crashing? ready?
kubectl describe pod       Events                      scheduled, pulled, started, backed off
kubectl logs --previous    logs of the last run        what the container printed before it exited
kubectl exec               a command inside it         needs a shell in the image
kubectl debug              a new container beside it   for an image with no shell

Try it

The tutorial ran these steps on 2026-11-18, at 09:39 (+06), on Linux, on the kind cluster qa-lab of Kubernetes Basics, with Docker 29.10.0, kind v0.33.0, and kubectl v1.37.2; the cluster ran Kubernetes v1.37.0. Names, UIDs, IP addresses, and ages differ on your machine. All the objects of the run were in the namespaces sec-lab and psa-lab, and step 7 deleted them. The Secret of the run holds a made-up value, not a real credential. The names of the objects, the image tags busybox:1.28 and nginx:1.16.1, and the sleep 3600 that keeps a Pod running are the tutorial's own choices.

1. See that a Secret is encoded, not encrypted. kubectl create namespace creates a namespace Source 28সোর্স 28. kubectl create secret generic creates a secret based on a file, directory, or specified literal value Source 21সোর্স 21, as in kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret Source 21সোর্স 21; you must use the generic subcommand to indicate an Opaque Secret type Source 1সোর্স 1; Opaque is the default Secret type Source 1সোর্স 1, and the DATA column shows the number of data items stored in the Secret Source 1সোর্স 1. -o jsonpath prints the fields defined in a jsonpath expression Source 27সোর্স 27, and the Secrets page decodes a data field with kubectl get secret secret-tiger-docker -o jsonpath='{.data.*}' | base64 -d Source 1সোর্স 1:

kubectl create namespace sec-lab
kubectl create secret generic db-creds -n sec-lab --from-literal=username=qa_user --from-literal=password=not-a-real-password
kubectl get secret db-creds -n sec-lab
kubectl get secret db-creds -n sec-lab -o jsonpath='{.data.password}{"\n"}'
kubectl get secret db-creds -n sec-lab -o jsonpath='{.data.password}' | base64 -d; echo

The output of the last three commands in the run:

NAME       TYPE     DATA   AGE
db-creds   Opaque   2      1s
bm90LWEtcmVhbC1wYXNzd29yZA==
not-a-real-password

The API printed the value as bm90LWEtcmVhbC1wYXNzd29yZA==, and base64 -d turned it back into not-a-real-password. The run then read the Secret out of etcd, as the docs do Source 3সোর্স 3: etcdctl runs in the etcd Pod that the kind cluster has on its control-plane node (see Kubernetes Architecture), started with kubectl exec, which runs a command in an existing pod Source 27সোর্স 27. The docs pass --cacert, --cert, and --key to connect to the etcd server Source 3সোর্স 3, and the run added the address --endpoints=https://127.0.0.1:2379 that the docs of etcd use Source 4সোর্স 4:

kubectl exec -n kube-system etcd-qa-lab-control-plane -- etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key get /registry/secrets/sec-lab/db-creds | hexdump -C

The page shows 6 of the 22 lines that the run printed: it leaves out the lines 00000030 to 000000f0, and the lines after 00000120:

00000000  2f 72 65 67 69 73 74 72  79 2f 73 65 63 72 65 74  |/registry/secret|
00000010  73 2f 73 65 63 2d 6c 61  62 2f 64 62 2d 63 72 65  |s/sec-lab/db-cre|
00000020  64 73 0a 6b 38 73 00 0a  0c 0a 02 76 31 12 06 53  |ds.k8s.....v1..S|
00000100  0a 08 70 61 73 73 77 6f  72 64 12 13 6e 6f 74 2d  |..password..not-|
00000110  61 2d 72 65 61 6c 2d 70  61 73 73 77 6f 72 64 12  |a-real-password.|
00000120  13 0a 08 75 73 65 72 6e  61 6d 65 12 07 71 61 5f  |...username..qa_|

The text column of the lines 00000100 and 00000110 spells not- and a-real-password: the value is stored in clear text. The stored value starts with k8s and a zero byte (a dot in the text column), and not with k8s:enc:aescbc:v1:, the prefix that the docs expect for an aescbc setup Source 3সোর্স 3. So the cluster of the run did not have encryption at rest enabled, which is the default Source 3সোর্স 3.

To use a Secret in a Pod, the manifest sec-app.yaml adds an environment variable for the Secret key, in the env[].valueFrom.secretKeyRef field Source 1সোর্স 1:

apiVersion: v1
kind: Pod
metadata:
  name: app
  namespace: sec-lab
spec:
  containers:
  - name: app
    image: busybox:1.28
    command: ["sleep", "3600"]
    env:
    - name: DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: db-creds
          key: password

kubectl wait waits for a specific condition on one or many resources Source 26সোর্স 26:

kubectl apply -f sec-app.yaml
kubectl wait --for=condition=Ready pod/app -n sec-lab --timeout=120s
kubectl exec -n sec-lab app -- printenv DB_PASSWORD

The container saw the decoded value:

not-a-real-password

2. Ask what an identity may do. kubectl create serviceaccount creates a service account with the specified name Source 22সোর্স 22. kubectl create role creates a role with a single rule Source 7সোর্স 7, and kubectl create rolebinding creates a role binding for a particular role or cluster role, with the service account in the format <namespace>:<name> Source 8সোর্স 8. kubectl auth can-i checks whether an action is allowed, and pairs nicely with impersonation, which is the --as flag Source 9সোর্স 9:

kubectl create serviceaccount tester -n sec-lab
kubectl create role pod-reader -n sec-lab --verb=get --verb=list --verb=watch --resource=pods
kubectl create rolebinding tester-reads-pods -n sec-lab --role=pod-reader --serviceaccount=sec-lab:tester
kubectl auth can-i list pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i delete pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i get secrets -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i list pods -n default --as=system:serviceaccount:sec-lab:tester
kubectl get pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl get secret db-creds -n sec-lab --as=system:serviceaccount:sec-lab:tester

The four can-i commands printed yes, no, no, and no, in that order:

Question, asked as the service account testerPrintedExit code
list pods in sec-labyes0
delete pods in sec-labno1
get secrets in sec-labno1
list pods in defaultno1

The output of the last two commands, get pods and get secret, which were run as the same identity:

NAME   READY   STATUS    RESTARTS   AGE
app    1/1     Running   0          2s
Error from server (Forbidden): secrets "db-creds" is forbidden: User "system:serviceaccount:sec-lab:tester" cannot get resource "secrets" in API group "" in the namespace "sec-lab"

The Role gave the permissions in the namespace sec-lab only Source 5সোর্স 5. The kubectl get pods command listed the Pod app, and the kubectl get secret command failed with Forbidden and exit code 1.

3. Make a namespace reject Pods that break a policy. The run set the enforce mode at the level restricted on a new namespace, with a label like the one in the docs Source 12সোর্স 12. kubectl run creates and runs a particular image in a pod Source 20সোর্স 20, and its --restart flag sets the restart policy of the Pod, with the legal values Always, OnFailure, and Never Source 20সোর্স 20. The plain Pod below breaks the policy; the manifest sec-restricted-ok.yaml sets the four fields of the table of the Restricted policy. The user ID 1000 is the tutorial's own choice: the Restricted policy says that containers must not set runAsUser to 0, and allows any non-zero value Source 10সোর্স 10:

apiVersion: v1
kind: Pod
metadata:
  name: restricted-ok
  namespace: psa-lab
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: app
    image: busybox:1.28
    command: ["sleep", "3600"]
    securityContext:
      allowPrivilegeEscalation: false
      capabilities:
        drop: ["ALL"]
kubectl create namespace psa-lab
kubectl label namespace psa-lab pod-security.kubernetes.io/enforce=restricted
kubectl run plain -n psa-lab --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl apply -f sec-restricted-ok.yaml
kubectl wait --for=condition=Ready pod/restricted-ok -n psa-lab --timeout=120s
kubectl get pods -n psa-lab

The output of the run, with the long error on one line:

Error from server (Forbidden): pods "plain" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "plain" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "plain" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "plain" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "plain" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
pod/restricted-ok created
NAME            READY   STATUS    RESTARTS   AGE
restricted-ok   1/1     Running   0          1s

The error names four violations. Each belongs to a control of the Restricted policy: allowPrivilegeEscalation, the capabilities, runAsNonRoot, and seccompProfile Source 10সোর্স 10. The compliant Pod was created and became ready.

4. Block traffic with a NetworkPolicy. kubectl create deployment creates a deployment with the specified name Source 23সোর্স 23, and kubectl expose exposes a resource as a new Kubernetes service Source 24সোর্স 24. kubectl rollout status shows the status of the rollout Source 25সোর্স 25, and the --labels flag of kubectl run takes comma separated labels to apply to the pod Source 20সোর্স 20. The run made two client Pods in sec-lab: tester-client has the label role=tester, and other-client has no label of its own:

kubectl create deployment web -n sec-lab --image=nginx:1.16.1
kubectl expose deployment web -n sec-lab --port=80
kubectl rollout status deployment/web -n sec-lab --timeout=120s
kubectl run tester-client -n sec-lab --image=busybox:1.28 --restart=Never --labels=role=tester -- sleep 3600
kubectl run other-client -n sec-lab --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl wait --for=condition=Ready pod/tester-client pod/other-client -n sec-lab --timeout=120s

The question that the run asked three times, with wget of the busybox image and a time-out of 5 seconds (-T 5), the tutorial's own choice: does the Service web answer?

kubectl exec -n sec-lab tester-client -- sh -c 'wget -qO- -T 5 http://web | grep "<title>"'
kubectl exec -n sec-lab other-client -- sh -c 'wget -qO- -T 5 http://web | grep "<title>"'

The run applied the two policies below, one after the other, and waited 5 seconds after each kubectl apply before it asked again; the 5 seconds are the tutorial's own choice. The first policy selects all pods and has Ingress in its policyTypes, and allows nothing in; the second one lets Pods with the label role=tester reach port 80 of the Pods with the label app=web Source 13সোর্স 13:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
  namespace: sec-lab
spec:
  podSelector: {}
  policyTypes:
  - Ingress
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: web-allow-testers
  namespace: sec-lab
spec:
  podSelector:
    matchLabels:
      app: web
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          role: tester
    ports:
    - protocol: TCP
      port: 80
kubectl apply -f sec-deny.yaml
kubectl apply -f sec-allow.yaml
kubectl get networkpolicy -n sec-lab

A request that was answered printed the first block below, and a request that was not answered printed the second one:

<title>Welcome to nginx!</title>
wget: download timed out
command terminated with exit code 1
When the question was askedtester-clientother-client
Before any policyansweredanswered
After default-deny-ingresstimed outtimed out
After web-allow-testersansweredtimed out

The last command printed the list of the policies:

NAME                   POD-SELECTOR   AGE
default-deny-ingress   <none>         26s
web-allow-testers      app=web        11s

In the run, <none> is what kubectl get networkpolicy printed as the pod selector of default-deny-ingress, whose podSelector is empty; the policy still applied to all pods, because an empty podSelector selects all pods in the namespace Source 13সোর্স 13. The cluster of the run kept the default network plugin of kind, kindnetd Source 14সোর্স 14, and the timeouts show that it enforced the policies.

5. Find out why a Pod keeps crashing. The syntax of kubectl run has a command and its arguments after -- Source 20সোর্স 20, and the restart policy of the Pod it creates defaults to Always Source 20সোর্স 20. The container of crashy prints a line, waits 1 second, prints an error, and exits with the code 1. kubectl wait can wait for a field: kubectl wait --for=jsonpath='{.status.phase}'=Running pod/busybox1 Source 26সোর্স 26. The run waited for the waiting reason CrashLoopBackOff, then looked at the Pod, the logs of the previous run of the container, and the events Source 15সোর্স 15 Source 18সোর্স 18. When you use kubectl to query a Pod with a container that is Terminated, you see a reason, an exit code, and the start and finish time for that container's period of execution Source 17সোর্স 17; the run read the exit code of the last termination with -o jsonpath Source 27সোর্স 27:

kubectl run crashy -n sec-lab --image=busybox:1.28 -- sh -c 'echo "connecting to db:5432"; sleep 1; echo "error: connection refused" >&2; exit 1'
kubectl wait --for=jsonpath='{.status.containerStatuses[0].state.waiting.reason}'=CrashLoopBackOff pod/crashy -n sec-lab --timeout=180s
kubectl get pod crashy -n sec-lab
kubectl logs crashy -n sec-lab --previous
kubectl get pod crashy -n sec-lab -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}{"\n"}'
kubectl describe pod crashy -n sec-lab

The output of the run; the page starts the kubectl describe pod output at the Events: line:

NAME     READY   STATUS             RESTARTS      AGE
crashy   0/1     CrashLoopBackOff   1 (15s ago)   18s
connecting to db:5432
error: connection refused
1
Events:
  Type     Reason     Age               From               Message
  ----     ------     ----              ----               -------
  Normal   Scheduled  18s               default-scheduler  Successfully assigned sec-lab/crashy to qa-lab-control-plane
  Warning  BackOff    14s               kubelet            spec.containers{crashy}: Back-off restarting failed container crashy in pod crashy_sec-lab(66716aaa-b482-44dd-8681-061302eca793)
  Normal   Pulled     1s (x3 over 18s)  kubelet            spec.containers{crashy}: Container image "busybox:1.28" already present on machine and can be accessed by the pod
  Normal   Created    0s (x3 over 18s)  kubelet            spec.containers{crashy}: Container created
  Normal   Started    0s (x3 over 18s)  kubelet            spec.containers{crashy}: Container started

The kubelet had started the container three times in 18 seconds, and the status was CrashLoopBackOff, the state in which the backoff delay mechanism is in effect Source 17সোর্স 17. The logs of the previous instance had the two lines that the container printed before it exited with the code 1.

6. Debug a container that has no shell. The docs create a Pod from the pause image, because it does not contain debugging utilities Source 16সোর্স 16: kubectl run ephemeral-demo --image=registry.k8s.io/pause:3.1 --restart=Never Source 16সোর্স 16. If you attempt to use kubectl exec to create a shell you will see an error because there is no shell in this container image, and you can instead add a debugging container using kubectl debug Source 16সোর্স 16. The syntax of the command allows a command after --: kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ] Source 19সোর্স 19, and -c, --container names the debug container Source 19সোর্স 19. The docs run it interactively, with -it Source 16সোর্স 16; the run had no terminal, so it started the debug container with the command ps and read the output with kubectl logs -c debugger:

kubectl run ephemeral-demo -n sec-lab --image=registry.k8s.io/pause:3.1 --restart=Never
kubectl wait --for=condition=Ready pod/ephemeral-demo -n sec-lab --timeout=120s
kubectl exec -n sec-lab ephemeral-demo -- sh
kubectl debug -n sec-lab ephemeral-demo --image=busybox:1.28 --target=ephemeral-demo -c debugger -- ps
kubectl logs -n sec-lab ephemeral-demo -c debugger

The output of the run:

error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "2415794a7b0bf0db76522ce709e3e05c8fbe574d38ae7e826f7aa3586cdd045f": OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH
Targeting container "ephemeral-demo". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
PID   USER     TIME  COMMAND
    1 root      0:00 /pause
   20 root      0:00 ps

The ps of the debug container listed the process /pause, the process of the container in the Pod that has no shell, because the run named it with --target Source 16সোর্স 16.

7. Clean up. kubectl delete namespaces deletes a namespace, and this deletes everything under the namespace Source 28সোর্স 28. kubectl delete also deletes resources by names, and --timeout is the length of time to wait before giving up on a delete Source 29সোর্স 29:

kubectl delete namespace sec-lab psa-lab --timeout=180s
kubectl get namespace sec-lab psa-lab
namespace "sec-lab" deleted
namespace "psa-lab" deleted
Error from server (NotFound): namespaces "sec-lab" not found
Error from server (NotFound): namespaces "psa-lab" not found

সহজ English

The tutorial ran these steps on 2026-11-18, at 09:39 (+06), on Linux, on the kind cluster qa-lab of Kubernetes Basics, with Docker 29.10.0, kind v0.33.0, and kubectl v1.37.2; the cluster ran Kubernetes v1.37.0. Names, UIDs, IP addresses, and ages will be different on your machine. Everything that the run made was in the namespaces sec-lab and psa-lab, and step 7 deleted them. The Secret of the run holds a made-up value, not a real credential. The names of the objects, the image tags busybox:1.28 and nginx:1.16.1, and the sleep 3600 that keeps a Pod running are the tutorial's own choices.

1. See that a Secret is encoded, not encrypted. kubectl create namespace makes a namespace Source 28সোর্স 28. kubectl create secret generic makes a secret from a file, a directory, or a given literal value Source 21সোর্স 21, as in kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret Source 21সোর্স 21; you must use the generic subcommand to get an Opaque Secret type Source 1সোর্স 1, Opaque is the default Secret type Source 1সোর্স 1, and the DATA column shows the number of data items stored in the Secret Source 1সোর্স 1. -o jsonpath prints the fields defined in a jsonpath expression Source 27সোর্স 27, and the Secrets page decodes a data field with kubectl get secret secret-tiger-docker -o jsonpath='{.data.*}' | base64 -d Source 1সোর্স 1:

kubectl create namespace sec-lab
kubectl create secret generic db-creds -n sec-lab --from-literal=username=qa_user --from-literal=password=not-a-real-password
kubectl get secret db-creds -n sec-lab
kubectl get secret db-creds -n sec-lab -o jsonpath='{.data.password}{"\n"}'
kubectl get secret db-creds -n sec-lab -o jsonpath='{.data.password}' | base64 -d; echo

The output of the last three commands in the run:

NAME       TYPE     DATA   AGE
db-creds   Opaque   2      1s
bm90LWEtcmVhbC1wYXNzd29yZA==
not-a-real-password

The API printed the value as bm90LWEtcmVhbC1wYXNzd29yZA==, and base64 -d turned it back into not-a-real-password. The run then read the Secret out of etcd, as the docs do Source 3সোর্স 3: etcdctl runs in the etcd Pod that the kind cluster has on its control-plane node (see Kubernetes Architecture), started with kubectl exec, which runs a command in an existing pod Source 27সোর্স 27. The docs pass --cacert, --cert, and --key to connect to the etcd server Source 3সোর্স 3, and the run added the address --endpoints=https://127.0.0.1:2379 that the docs of etcd use Source 4সোর্স 4:

kubectl exec -n kube-system etcd-qa-lab-control-plane -- etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key get /registry/secrets/sec-lab/db-creds | hexdump -C

The page shows 6 of the 22 lines that the run printed: it leaves out the lines 00000030 to 000000f0, and the lines after 00000120:

00000000  2f 72 65 67 69 73 74 72  79 2f 73 65 63 72 65 74  |/registry/secret|
00000010  73 2f 73 65 63 2d 6c 61  62 2f 64 62 2d 63 72 65  |s/sec-lab/db-cre|
00000020  64 73 0a 6b 38 73 00 0a  0c 0a 02 76 31 12 06 53  |ds.k8s.....v1..S|
00000100  0a 08 70 61 73 73 77 6f  72 64 12 13 6e 6f 74 2d  |..password..not-|
00000110  61 2d 72 65 61 6c 2d 70  61 73 73 77 6f 72 64 12  |a-real-password.|
00000120  13 0a 08 75 73 65 72 6e  61 6d 65 12 07 71 61 5f  |...username..qa_|

The text column of the lines 00000100 and 00000110 spells not- and a-real-password: the value is stored in clear text. The stored value starts with k8s and a zero byte (a dot in the text column), and not with k8s:enc:aescbc:v1:, the start that the docs expect for an aescbc setup Source 3সোর্স 3. So the cluster of the run did not have encryption at rest enabled, which is the default Source 3সোর্স 3.

To use a Secret in a Pod, the manifest sec-app.yaml adds an environment variable for the Secret key, in the env[].valueFrom.secretKeyRef field Source 1সোর্স 1:

apiVersion: v1
kind: Pod
metadata:
  name: app
  namespace: sec-lab
spec:
  containers:
  - name: app
    image: busybox:1.28
    command: ["sleep", "3600"]
    env:
    - name: DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: db-creds
          key: password

kubectl wait waits for a specific condition on one or many resources Source 26সোর্স 26:

kubectl apply -f sec-app.yaml
kubectl wait --for=condition=Ready pod/app -n sec-lab --timeout=120s
kubectl exec -n sec-lab app -- printenv DB_PASSWORD

The container saw the decoded value:

not-a-real-password

2. Ask what an identity may do. kubectl create serviceaccount makes a service account with the given name Source 22সোর্স 22. kubectl create role makes a role with a single rule Source 7সোর্স 7, and kubectl create rolebinding makes a role binding for a particular role or cluster role, with the service account written as <namespace>:<name> Source 8সোর্স 8. kubectl auth can-i checks whether an action is allowed, and pairs nicely with impersonation, which is the --as flag Source 9সোর্স 9:

kubectl create serviceaccount tester -n sec-lab
kubectl create role pod-reader -n sec-lab --verb=get --verb=list --verb=watch --resource=pods
kubectl create rolebinding tester-reads-pods -n sec-lab --role=pod-reader --serviceaccount=sec-lab:tester
kubectl auth can-i list pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i delete pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i get secrets -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i list pods -n default --as=system:serviceaccount:sec-lab:tester
kubectl get pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl get secret db-creds -n sec-lab --as=system:serviceaccount:sec-lab:tester

The four can-i commands printed yes, no, no, and no, in that order:

Question, asked as the service account testerPrintedExit code
list pods in sec-labyes0
delete pods in sec-labno1
get secrets in sec-labno1
list pods in defaultno1

The output of the last two commands, get pods and get secret, which were run as the same identity:

NAME   READY   STATUS    RESTARTS   AGE
app    1/1     Running   0          2s
Error from server (Forbidden): secrets "db-creds" is forbidden: User "system:serviceaccount:sec-lab:tester" cannot get resource "secrets" in API group "" in the namespace "sec-lab"

The Role gave permissions in the namespace sec-lab only Source 5সোর্স 5. The kubectl get pods command listed the Pod app, and the kubectl get secret command failed with Forbidden and exit code 1.

3. Make a namespace reject Pods that break a policy. The run set the enforce mode at the level restricted on a new namespace, with a label like the one in the docs Source 12সোর্স 12. kubectl run creates and runs a particular image in a pod Source 20সোর্স 20, and its --restart flag sets the restart policy of the Pod, with the legal values Always, OnFailure, and Never Source 20সোর্স 20. The plain Pod below breaks the policy; the manifest sec-restricted-ok.yaml sets the four fields of the table of the Restricted policy. The user ID 1000 is the tutorial's own choice: the Restricted policy says that containers must not set runAsUser to 0, and allows any non-zero value Source 10সোর্স 10:

apiVersion: v1
kind: Pod
metadata:
  name: restricted-ok
  namespace: psa-lab
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: app
    image: busybox:1.28
    command: ["sleep", "3600"]
    securityContext:
      allowPrivilegeEscalation: false
      capabilities:
        drop: ["ALL"]
kubectl create namespace psa-lab
kubectl label namespace psa-lab pod-security.kubernetes.io/enforce=restricted
kubectl run plain -n psa-lab --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl apply -f sec-restricted-ok.yaml
kubectl wait --for=condition=Ready pod/restricted-ok -n psa-lab --timeout=120s
kubectl get pods -n psa-lab

The output of the run, with the long error on one line:

Error from server (Forbidden): pods "plain" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "plain" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "plain" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "plain" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "plain" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
pod/restricted-ok created
NAME            READY   STATUS    RESTARTS   AGE
restricted-ok   1/1     Running   0          1s

The error names four violations. Each belongs to a control of the Restricted policy: allowPrivilegeEscalation, the capabilities, runAsNonRoot, and seccompProfile Source 10সোর্স 10. The compliant Pod was created and became ready.

4. Block traffic with a NetworkPolicy. kubectl create deployment makes a deployment with the given name Source 23সোর্স 23, and kubectl expose exposes a resource as a new Kubernetes service Source 24সোর্স 24. kubectl rollout status shows the status of the rollout Source 25সোর্স 25, and the --labels flag of kubectl run takes comma separated labels to apply to the pod Source 20সোর্স 20. The run made two client Pods in sec-lab: tester-client has the label role=tester, and other-client has no label of its own:

kubectl create deployment web -n sec-lab --image=nginx:1.16.1
kubectl expose deployment web -n sec-lab --port=80
kubectl rollout status deployment/web -n sec-lab --timeout=120s
kubectl run tester-client -n sec-lab --image=busybox:1.28 --restart=Never --labels=role=tester -- sleep 3600
kubectl run other-client -n sec-lab --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl wait --for=condition=Ready pod/tester-client pod/other-client -n sec-lab --timeout=120s

The question that the run asked three times, with wget of the busybox image and a time-out of 5 seconds (-T 5), the tutorial's own choice: does the Service web answer?

kubectl exec -n sec-lab tester-client -- sh -c 'wget -qO- -T 5 http://web | grep "<title>"'
kubectl exec -n sec-lab other-client -- sh -c 'wget -qO- -T 5 http://web | grep "<title>"'

The run applied the two policies below, one after the other, and waited 5 seconds after each kubectl apply before it asked again; the 5 seconds are the tutorial's own choice. The first policy selects all pods and has Ingress in its policyTypes, and lets nothing in; the second one lets Pods with the label role=tester reach port 80 of the Pods with the label app=web Source 13সোর্স 13:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
  namespace: sec-lab
spec:
  podSelector: {}
  policyTypes:
  - Ingress
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: web-allow-testers
  namespace: sec-lab
spec:
  podSelector:
    matchLabels:
      app: web
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          role: tester
    ports:
    - protocol: TCP
      port: 80
kubectl apply -f sec-deny.yaml
kubectl apply -f sec-allow.yaml
kubectl get networkpolicy -n sec-lab

A request that was answered printed the first block below, and a request that was not answered printed the second one:

<title>Welcome to nginx!</title>
wget: download timed out
command terminated with exit code 1
When the question was askedtester-clientother-client
Before any policyansweredanswered
After default-deny-ingresstimed outtimed out
After web-allow-testersansweredtimed out

The last command printed the list of the policies:

NAME                   POD-SELECTOR   AGE
default-deny-ingress   <none>         26s
web-allow-testers      app=web        11s

In the run, <none> is what kubectl get networkpolicy printed as the pod selector of default-deny-ingress, whose podSelector is empty; the policy still applied to all pods, because an empty podSelector selects all pods in the namespace Source 13সোর্স 13. The cluster of the run kept the default network plugin of kind, kindnetd Source 14সোর্স 14, and the timeouts show that it enforced the policies.

5. Find out why a Pod keeps crashing. The syntax of kubectl run has a command and its arguments after -- Source 20সোর্স 20, and the restart policy of the Pod it creates defaults to Always Source 20সোর্স 20. The container of crashy prints a line, waits 1 second, prints an error, and exits with the code 1. kubectl wait can wait for a field: kubectl wait --for=jsonpath='{.status.phase}'=Running pod/busybox1 Source 26সোর্স 26. The run waited for the waiting reason CrashLoopBackOff, then looked at the Pod, the logs of the previous run of the container, and the events Source 15সোর্স 15 Source 18সোর্স 18. When you use kubectl to query a Pod with a container that is Terminated, you see a reason, an exit code, and the start and finish time of that container's period of execution Source 17সোর্স 17; the run read the exit code of the last termination with -o jsonpath Source 27সোর্স 27:

kubectl run crashy -n sec-lab --image=busybox:1.28 -- sh -c 'echo "connecting to db:5432"; sleep 1; echo "error: connection refused" >&2; exit 1'
kubectl wait --for=jsonpath='{.status.containerStatuses[0].state.waiting.reason}'=CrashLoopBackOff pod/crashy -n sec-lab --timeout=180s
kubectl get pod crashy -n sec-lab
kubectl logs crashy -n sec-lab --previous
kubectl get pod crashy -n sec-lab -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}{"\n"}'
kubectl describe pod crashy -n sec-lab

The output of the run; the page starts the kubectl describe pod output at the Events: line:

NAME     READY   STATUS             RESTARTS      AGE
crashy   0/1     CrashLoopBackOff   1 (15s ago)   18s
connecting to db:5432
error: connection refused
1
Events:
  Type     Reason     Age               From               Message
  ----     ------     ----              ----               -------
  Normal   Scheduled  18s               default-scheduler  Successfully assigned sec-lab/crashy to qa-lab-control-plane
  Warning  BackOff    14s               kubelet            spec.containers{crashy}: Back-off restarting failed container crashy in pod crashy_sec-lab(66716aaa-b482-44dd-8681-061302eca793)
  Normal   Pulled     1s (x3 over 18s)  kubelet            spec.containers{crashy}: Container image "busybox:1.28" already present on machine and can be accessed by the pod
  Normal   Created    0s (x3 over 18s)  kubelet            spec.containers{crashy}: Container created
  Normal   Started    0s (x3 over 18s)  kubelet            spec.containers{crashy}: Container started

The kubelet had started the container three times in 18 seconds, and the status was CrashLoopBackOff, the state in which the backoff delay mechanism is in effect Source 17সোর্স 17. The logs of the previous instance had the two lines that the container printed before it exited with the code 1.

6. Debug a container that has no shell. The docs create a Pod from the pause image, because it does not contain debugging utilities Source 16সোর্স 16: kubectl run ephemeral-demo --image=registry.k8s.io/pause:3.1 --restart=Never Source 16সোর্স 16. If you try to use kubectl exec to open a shell, you will see an error, because there is no shell in this container image, and you can instead add a debugging container using kubectl debug Source 16সোর্স 16. The syntax of the command allows a command after --: kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ] Source 19সোর্স 19, and -c, --container names the debug container Source 19সোর্স 19. The docs run it interactively, with -it Source 16সোর্স 16; the run had no terminal, so it started the debug container with the command ps and read the output with kubectl logs -c debugger:

kubectl run ephemeral-demo -n sec-lab --image=registry.k8s.io/pause:3.1 --restart=Never
kubectl wait --for=condition=Ready pod/ephemeral-demo -n sec-lab --timeout=120s
kubectl exec -n sec-lab ephemeral-demo -- sh
kubectl debug -n sec-lab ephemeral-demo --image=busybox:1.28 --target=ephemeral-demo -c debugger -- ps
kubectl logs -n sec-lab ephemeral-demo -c debugger

The output of the run:

error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "2415794a7b0bf0db76522ce709e3e05c8fbe574d38ae7e826f7aa3586cdd045f": OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH
Targeting container "ephemeral-demo". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
PID   USER     TIME  COMMAND
    1 root      0:00 /pause
   20 root      0:00 ps

The ps of the debug container listed the process /pause, the process of the container in the Pod that has no shell, because the run named it with --target Source 16সোর্স 16.

7. Clean up. kubectl delete namespaces deletes a namespace, and this deletes everything under the namespace Source 28সোর্স 28. kubectl delete also deletes resources by names, and --timeout is how long to wait before giving up on a delete Source 29সোর্স 29:

kubectl delete namespace sec-lab psa-lab --timeout=180s
kubectl get namespace sec-lab psa-lab
namespace "sec-lab" deleted
namespace "psa-lab" deleted
Error from server (NotFound): namespaces "sec-lab" not found
Error from server (NotFound): namespaces "psa-lab" not found

বাংলা ব্যাখ্যা

টিউটোরিয়াল এই ধাপগুলো 2026-11-18 তারিখে, 09:39-এ (+06), Linux-এ, Kubernetes Basics-এর kind cluster qa-lab-এ, Docker 29.10.0, kind v0.33.0 আর kubectl v1.37.2 দিয়ে চালিয়েছে; cluster-এ Kubernetes v1.37.0 চলছিল। আপনার machine-এ নাম, UID, IP address আর বয়স আলাদা হবে। run-এর সব object ছিল sec-lab আর psa-lab namespace-এ, আর ধাপ ৭ সেগুলো মুছে দিয়েছে। run-এর Secret-এ একটা বানানো মান আছে, কোনো আসল credential নয়। object-গুলোর নাম, image tag busybox:1.28 আর nginx:1.16.1, আর একটা Pod চালু রাখার sleep 3600 টিউটোরিয়ালের নিজের বেছে নেওয়া।

১. দেখুন একটা Secret encoded, encrypted নয়। kubectl create namespace একটা namespace তৈরি করে Source 28সোর্স 28। kubectl create secret generic একটা file, directory বা নির্দিষ্ট literal মানের ওপর ভিত্তি করে secret তৈরি করে Source 21সোর্স 21, যেমন kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret Source 21সোর্স 21; Opaque Secret type বোঝাতে generic subcommand ব্যবহার করতে হয় Source 1সোর্স 1, Opaque হলো default Secret type Source 1সোর্স 1, আর DATA column Secret-এ রাখা data item-এর সংখ্যা দেখায় Source 1সোর্স 1। -o jsonpath jsonpath expression-এ ঠিক করা field প্রিন্ট করে Source 27সোর্স 27, আর Secrets পাতা একটা data field decode করে kubectl get secret secret-tiger-docker -o jsonpath='{.data.*}' | base64 -d দিয়ে Source 1সোর্স 1:

kubectl create namespace sec-lab
kubectl create secret generic db-creds -n sec-lab --from-literal=username=qa_user --from-literal=password=not-a-real-password
kubectl get secret db-creds -n sec-lab
kubectl get secret db-creds -n sec-lab -o jsonpath='{.data.password}{"\n"}'
kubectl get secret db-creds -n sec-lab -o jsonpath='{.data.password}' | base64 -d; echo

run-এ শেষ তিনটা command-এর output:

NAME       TYPE     DATA   AGE
db-creds   Opaque   2      1s
bm90LWEtcmVhbC1wYXNzd29yZA==
not-a-real-password

API মানটা প্রিন্ট করেছে bm90LWEtcmVhbC1wYXNzd29yZA== হিসেবে, আর base64 -d সেটাকে আবার not-a-real-password বানিয়েছে। এরপর run Secret-টা etcd থেকে পড়েছে, যেমন docs করে Source 3সোর্স 3: etcdctl চলে সেই etcd Pod-এ, যা kind cluster-এর control-plane node-এ আছে (Kubernetes Architecture দেখুন), আর সেটা শুরু হয়েছে kubectl exec দিয়ে, যা একটা বিদ্যমান pod-এ command চালায় Source 27সোর্স 27। etcd server-এর সাথে সংযোগের জন্য docs --cacert, --cert আর --key দেয় Source 3সোর্স 3, আর run যোগ করেছে --endpoints=https://127.0.0.1:2379 ঠিকানা, যা etcd-র docs ব্যবহার করে Source 4সোর্স 4:

kubectl exec -n kube-system etcd-qa-lab-control-plane -- etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key get /registry/secrets/sec-lab/db-creds | hexdump -C

run যে 22টা line প্রিন্ট করেছে, তার 6টা পাতায় আছে: 00000030 থেকে 000000f0 পর্যন্ত line আর 00000120-এর পরের line-গুলো বাদ দেওয়া হয়েছে:

00000000  2f 72 65 67 69 73 74 72  79 2f 73 65 63 72 65 74  |/registry/secret|
00000010  73 2f 73 65 63 2d 6c 61  62 2f 64 62 2d 63 72 65  |s/sec-lab/db-cre|
00000020  64 73 0a 6b 38 73 00 0a  0c 0a 02 76 31 12 06 53  |ds.k8s.....v1..S|
00000100  0a 08 70 61 73 73 77 6f  72 64 12 13 6e 6f 74 2d  |..password..not-|
00000110  61 2d 72 65 61 6c 2d 70  61 73 73 77 6f 72 64 12  |a-real-password.|
00000120  13 0a 08 75 73 65 72 6e  61 6d 65 12 07 71 61 5f  |...username..qa_|

00000100 আর 00000110 line-এর text column বানান করছে not- আর a-real-password: মানটা clear text-এ রাখা আছে। stored মান শুরু হয়েছে k8s আর একটা zero byte দিয়ে (text column-এ একটা বিন্দু), k8s:enc:aescbc:v1: দিয়ে নয়, যে শুরু docs একটা aescbc setup-এর জন্য আশা করে Source 3সোর্স 3। তাই run-এর cluster-এ encryption at rest চালু ছিল না, যা ডিফল্ট Source 3সোর্স 3।

একটা Pod-এ Secret ব্যবহার করতে manifest sec-app.yaml Secret key-এর জন্য একটা environment variable যোগ করে, env[].valueFrom.secretKeyRef field-এ Source 1সোর্স 1:

apiVersion: v1
kind: Pod
metadata:
  name: app
  namespace: sec-lab
spec:
  containers:
  - name: app
    image: busybox:1.28
    command: ["sleep", "3600"]
    env:
    - name: DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: db-creds
          key: password

kubectl wait এক বা একাধিক resource-এর একটা নির্দিষ্ট condition-এর জন্য অপেক্ষা করে Source 26সোর্স 26:

kubectl apply -f sec-app.yaml
kubectl wait --for=condition=Ready pod/app -n sec-lab --timeout=120s
kubectl exec -n sec-lab app -- printenv DB_PASSWORD

container decode করা মানটা দেখেছে:

not-a-real-password

২. জিজ্ঞেস করুন একটা identity কী করতে পারে। kubectl create serviceaccount দেওয়া নামে একটা service account তৈরি করে Source 22সোর্স 22। kubectl create role একটা মাত্র rule-সহ role তৈরি করে Source 7সোর্স 7, আর kubectl create rolebinding একটা নির্দিষ্ট role বা cluster role-এর জন্য role binding তৈরি করে, service account লেখা হয় <namespace>:<name> format-এ Source 8সোর্স 8। kubectl auth can-i একটা action অনুমোদিত কি না যাচাই করে, আর impersonation-এর সাথে ভালো মানায়, যা --as flag Source 9সোর্স 9:

kubectl create serviceaccount tester -n sec-lab
kubectl create role pod-reader -n sec-lab --verb=get --verb=list --verb=watch --resource=pods
kubectl create rolebinding tester-reads-pods -n sec-lab --role=pod-reader --serviceaccount=sec-lab:tester
kubectl auth can-i list pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i delete pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i get secrets -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl auth can-i list pods -n default --as=system:serviceaccount:sec-lab:tester
kubectl get pods -n sec-lab --as=system:serviceaccount:sec-lab:tester
kubectl get secret db-creds -n sec-lab --as=system:serviceaccount:sec-lab:tester

চারটা can-i command প্রিন্ট করেছে yes, no, no আর no, এই ক্রমে:

প্রশ্ন, service account tester হিসেবে করাপ্রিন্ট হয়েছেExit code
sec-lab-এ list podsyes0
sec-lab-এ delete podsno1
sec-lab-এ get secretsno1
default-এ list podsno1

শেষ দুটো command, get pods আর get secret-এর output, যা একই identity হিসেবে চালানো হয়েছে:

NAME   READY   STATUS    RESTARTS   AGE
app    1/1     Running   0          2s
Error from server (Forbidden): secrets "db-creds" is forbidden: User "system:serviceaccount:sec-lab:tester" cannot get resource "secrets" in API group "" in the namespace "sec-lab"

Role শুধু sec-lab namespace-এ permission দিয়েছে Source 5সোর্স 5। kubectl get pods command Pod app তালিকাভুক্ত করেছে, আর kubectl get secret command Forbidden আর exit code 1 দিয়ে ব্যর্থ হয়েছে।

৩. একটা namespace-কে policy ভাঙা Pod reject করান। run একটা নতুন namespace-এ enforce mode সেট করেছে restricted level-এ, docs-এর মতো একটা label দিয়ে Source 12সোর্স 12। kubectl run একটা নির্দিষ্ট image একটা pod-এ তৈরি করে চালায় Source 20সোর্স 20, আর তার --restart flag Pod-এর restart policy ঠিক করে, বৈধ মান Always, OnFailure আর Never Source 20সোর্স 20। নিচের সাধারণ Pod policy ভাঙে; manifest sec-restricted-ok.yaml Restricted policy-র table-এর চারটা field সেট করে। user ID 1000 টিউটোরিয়ালের নিজের বেছে নেওয়া: Restricted policy বলে container runAsUser 0 সেট করতে পারবে না, আর যেকোনো non-zero মান অনুমোদিত Source 10সোর্স 10:

apiVersion: v1
kind: Pod
metadata:
  name: restricted-ok
  namespace: psa-lab
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    seccompProfile:
      type: RuntimeDefault
  containers:
  - name: app
    image: busybox:1.28
    command: ["sleep", "3600"]
    securityContext:
      allowPrivilegeEscalation: false
      capabilities:
        drop: ["ALL"]
kubectl create namespace psa-lab
kubectl label namespace psa-lab pod-security.kubernetes.io/enforce=restricted
kubectl run plain -n psa-lab --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl apply -f sec-restricted-ok.yaml
kubectl wait --for=condition=Ready pod/restricted-ok -n psa-lab --timeout=120s
kubectl get pods -n psa-lab

run-এর output, লম্বা error এক line-এ:

Error from server (Forbidden): pods "plain" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "plain" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "plain" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "plain" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "plain" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
pod/restricted-ok created
NAME            READY   STATUS    RESTARTS   AGE
restricted-ok   1/1     Running   0          1s

error চারটা violation-এর নাম বলে। প্রতিটা Restricted policy-র একটা control-এর: allowPrivilegeEscalation, capabilities, runAsNonRoot আর seccompProfile Source 10সোর্স 10। নিয়ম মানা Pod-টা তৈরি হয়েছে আর ready হয়েছে।

৪. NetworkPolicy দিয়ে traffic আটকান। kubectl create deployment দেওয়া নামে একটা deployment তৈরি করে Source 23সোর্স 23, আর kubectl expose একটা resource-কে নতুন Kubernetes service হিসেবে প্রকাশ করে Source 24সোর্স 24। kubectl rollout status rollout-এর status দেখায় Source 25সোর্স 25, আর kubectl run-এর --labels flag pod-এ দেওয়ার জন্য কমা-দিয়ে-আলাদা-করা label নেয় Source 20সোর্স 20। run sec-lab-এ দুটো client Pod বানিয়েছে: tester-client-এর label role=tester, আর other-client-এর নিজের কোনো label নেই:

kubectl create deployment web -n sec-lab --image=nginx:1.16.1
kubectl expose deployment web -n sec-lab --port=80
kubectl rollout status deployment/web -n sec-lab --timeout=120s
kubectl run tester-client -n sec-lab --image=busybox:1.28 --restart=Never --labels=role=tester -- sleep 3600
kubectl run other-client -n sec-lab --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl wait --for=condition=Ready pod/tester-client pod/other-client -n sec-lab --timeout=120s

যে প্রশ্ন run তিনবার করেছে, busybox image-এর wget আর 5 সেকেন্ডের time-out (-T 5) দিয়ে, যা টিউটোরিয়ালের নিজের বেছে নেওয়া: Service web কি উত্তর দেয়?

kubectl exec -n sec-lab tester-client -- sh -c 'wget -qO- -T 5 http://web | grep "<title>"'
kubectl exec -n sec-lab other-client -- sh -c 'wget -qO- -T 5 http://web | grep "<title>"'

run নিচের দুটো policy একটার পর একটা apply করেছে, আর প্রতিটা kubectl apply-এর পরে আবার জিজ্ঞেস করার আগে 5 সেকেন্ড অপেক্ষা করেছে; 5 সেকেন্ড টিউটোরিয়ালের নিজের বেছে নেওয়া। প্রথম policy সব pod select করে আর তার policyTypes-এ Ingress আছে, আর ভেতরে কিছু ঢুকতে দেয় না; দ্বিতীয়টা role=tester label-ওয়ালা Pod-কে app=web label-ওয়ালা Pod-এর port 80-এ পৌঁছাতে দেয় Source 13সোর্স 13:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
  namespace: sec-lab
spec:
  podSelector: {}
  policyTypes:
  - Ingress
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: web-allow-testers
  namespace: sec-lab
spec:
  podSelector:
    matchLabels:
      app: web
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          role: tester
    ports:
    - protocol: TCP
      port: 80
kubectl apply -f sec-deny.yaml
kubectl apply -f sec-allow.yaml
kubectl get networkpolicy -n sec-lab

যে request-এর উত্তর এসেছে, সেটা নিচের প্রথম block প্রিন্ট করেছে, আর যে request-এর উত্তর আসেনি, সেটা দ্বিতীয়টা:

<title>Welcome to nginx!</title>
wget: download timed out
command terminated with exit code 1
প্রশ্নটা কখন করা হয়েছেtester-clientother-client
কোনো policy-র আগেউত্তর এসেছেউত্তর এসেছে
default-deny-ingress-এর পরেtime outtime out
web-allow-testers-এর পরেউত্তর এসেছেtime out

শেষ command policy-গুলোর তালিকা প্রিন্ট করেছে:

NAME                   POD-SELECTOR   AGE
default-deny-ingress   <none>         26s
web-allow-testers      app=web        11s

run-এ <none> হলো kubectl get networkpolicy যা default-deny-ingress-এর pod selector হিসেবে প্রিন্ট করেছে, যার podSelector খালি; policy তবুও সব pod-এ প্রযোজ্য হয়েছে, কারণ খালি podSelector namespace-এর সব pod select করে Source 13সোর্স 13। run-এর cluster kind-এর default network plugin kindnetd রেখেছিল Source 14সোর্স 14, আর time-out দেখায় সেটা policy-গুলো প্রয়োগ করেছে।

৫. জানুন একটা Pod কেন বারবার crash করে। kubectl run-এর syntax-এ ---এর পরে একটা command আর তার argument থাকে Source 20সোর্স 20, আর সে যে Pod বানায় তার restart policy ডিফল্টভাবে Always Source 20সোর্স 20। crashy-র container একটা line প্রিন্ট করে, 1 সেকেন্ড অপেক্ষা করে, একটা error প্রিন্ট করে, আর exit code 1 দিয়ে বেরিয়ে যায়। kubectl wait একটা field-এর জন্য অপেক্ষা করতে পারে: kubectl wait --for=jsonpath='{.status.phase}'=Running pod/busybox1 Source 26সোর্স 26। run অপেক্ষা করেছে waiting reason CrashLoopBackOff-এর জন্য, তারপর দেখেছে Pod, container-এর আগের run-এর log আর event Source 15সোর্স 15 Source 18সোর্স 18। kubectl দিয়ে এমন একটা Pod জিজ্ঞেস করলে, যার একটা container Terminated, আপনি একটা reason, একটা exit code, আর সেই container-এর execution-এর সময়কালের শুরু ও শেষের সময় দেখেন Source 17সোর্স 17; run শেষ termination-এর exit code পড়েছে -o jsonpath দিয়ে Source 27সোর্স 27:

kubectl run crashy -n sec-lab --image=busybox:1.28 -- sh -c 'echo "connecting to db:5432"; sleep 1; echo "error: connection refused" >&2; exit 1'
kubectl wait --for=jsonpath='{.status.containerStatuses[0].state.waiting.reason}'=CrashLoopBackOff pod/crashy -n sec-lab --timeout=180s
kubectl get pod crashy -n sec-lab
kubectl logs crashy -n sec-lab --previous
kubectl get pod crashy -n sec-lab -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}{"\n"}'
kubectl describe pod crashy -n sec-lab

run-এর output; পাতাটা kubectl describe pod output শুরু করেছে Events: line থেকে:

NAME     READY   STATUS             RESTARTS      AGE
crashy   0/1     CrashLoopBackOff   1 (15s ago)   18s
connecting to db:5432
error: connection refused
1
Events:
  Type     Reason     Age               From               Message
  ----     ------     ----              ----               -------
  Normal   Scheduled  18s               default-scheduler  Successfully assigned sec-lab/crashy to qa-lab-control-plane
  Warning  BackOff    14s               kubelet            spec.containers{crashy}: Back-off restarting failed container crashy in pod crashy_sec-lab(66716aaa-b482-44dd-8681-061302eca793)
  Normal   Pulled     1s (x3 over 18s)  kubelet            spec.containers{crashy}: Container image "busybox:1.28" already present on machine and can be accessed by the pod
  Normal   Created    0s (x3 over 18s)  kubelet            spec.containers{crashy}: Container created
  Normal   Started    0s (x3 over 18s)  kubelet            spec.containers{crashy}: Container started

kubelet 18 সেকেন্ডে container তিনবার চালু করেছিল, আর status ছিল CrashLoopBackOff, যে state-এ backoff delay mechanism কার্যকর Source 17সোর্স 17। আগের instance-এর log-এ ছিল সেই দুটো line, যা container exit code 1 দিয়ে বেরোনোর আগে প্রিন্ট করেছিল।

৬. shell নেই এমন একটা container debug করুন। docs pause image থেকে একটা Pod বানায়, কারণ তাতে debugging utility নেই Source 16সোর্স 16: kubectl run ephemeral-demo --image=registry.k8s.io/pause:3.1 --restart=Never Source 16সোর্স 16। kubectl exec দিয়ে shell খুলতে গেলে আপনি একটা error দেখবেন, কারণ এই container image-এ কোনো shell নেই, আর তার বদলে আপনি kubectl debug দিয়ে একটা debugging container যোগ করতে পারেন Source 16সোর্স 16। command-এর syntax ---এর পরে একটা command-এর অনুমতি দেয়: kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ] Source 19সোর্স 19, আর -c, --container debug container-এর নাম দেয় Source 19সোর্স 19। docs এটা interactive-ভাবে চালায়, -it দিয়ে Source 16সোর্স 16; run-এর কোনো terminal ছিল না, তাই সে debug container চালু করেছে ps command দিয়ে আর output পড়েছে kubectl logs -c debugger দিয়ে:

kubectl run ephemeral-demo -n sec-lab --image=registry.k8s.io/pause:3.1 --restart=Never
kubectl wait --for=condition=Ready pod/ephemeral-demo -n sec-lab --timeout=120s
kubectl exec -n sec-lab ephemeral-demo -- sh
kubectl debug -n sec-lab ephemeral-demo --image=busybox:1.28 --target=ephemeral-demo -c debugger -- ps
kubectl logs -n sec-lab ephemeral-demo -c debugger

run-এর output:

error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "2415794a7b0bf0db76522ce709e3e05c8fbe574d38ae7e826f7aa3586cdd045f": OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH
Targeting container "ephemeral-demo". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
PID   USER     TIME  COMMAND
    1 root      0:00 /pause
   20 root      0:00 ps

debug container-এর ps process /pause তালিকাভুক্ত করেছে, shell-ছাড়া Pod-এর container-এর process, কারণ run সেটাকে --target দিয়ে নাম দিয়েছিল Source 16সোর্স 16।

৭. পরিষ্কার করুন। kubectl delete namespaces একটা namespace মোছে, আর এতে namespace-এর ভেতরের সবকিছু মুছে যায় Source 28সোর্স 28। kubectl delete নাম দিয়েও resource মোছে, আর --timeout হলো delete ছেড়ে দেওয়ার আগে কতক্ষণ অপেক্ষা করা হবে Source 29সোর্স 29:

kubectl delete namespace sec-lab psa-lab --timeout=180s
kubectl get namespace sec-lab psa-lab
namespace "sec-lab" deleted
namespace "psa-lab" deleted
Error from server (NotFound): namespaces "sec-lab" not found
Error from server (NotFound): namespaces "psa-lab" not found

How a tester uses it

Read a Secret the way anyone with access would. Anyone with API access can retrieve or modify a Secret, and so can anyone with access to etcd Source 1সোর্স 1. In step 1, one command turned the base64 value back into the password, and the password was readable in etcd. To test encryption at rest, read the Secret out of etcd and look at the start of the stored value; the docs expect k8s:enc:aescbc:v1: for an aescbc setup Source 3সোর্স 3.

Ask as the identity under test, and ask for the "no" answers too. kubectl auth can-i pairs nicely with impersonation Source 9সোর্স 9. In step 2, the identity could list Pods in its own namespace, and could not delete Pods, get Secrets, or list Pods in default; a Role always sets permissions within a particular namespace Source 5সোর্স 5.

Read the whole rejection. With the enforce mode, policy violations will cause the pod to be rejected Source 11সোর্স 11. In step 3, one message named four violations at once, and each one is a control of the Restricted policy Source 10সোর্স 10. A Deployment is not rejected as such: enforce mode is not applied to workload resources, only to the resulting pod objects Source 11সোর্স 11, so look at the Pods.

Prove a NetworkPolicy with a request that should fail. Creating a NetworkPolicy resource without a controller that implements it will have no effect Source 13সোর্স 13, and kind lets you install a different CNI Source 14সোর্স 14. In step 4, the same request changed from an answer to a timeout after the policy, and the label of the client decided which client was let in again.

Go down the list of checks in order. kubectl describe shows the current state and the recent events Source 15সোর্স 15, kubectl logs shows the logs of the container Source 17সোর্স 17, and --previous shows the previous instance Source 18সোর্স 18. kubectl debug helps when kubectl exec is insufficient Source 16সোর্স 16. In step 5, the exit code 1 and the two lines of the previous logs named the failure that the container printed.

Check that you may debug at all. If you run kubectl debug to add an ephemeral container without the required permission, you will see an error similar to Error from server (Forbidden) Source 16সোর্স 16. When granting permission to add ephemeral containers to Pods governed by the baseline or restricted policy, the docs say to choose a matching debugging profile such as --profile=baseline or --profile=restricted with kubectl debug Source 16সোর্স 16.

সহজ English

Read a Secret the way anyone with access would. Anyone with access to the API can read or change a Secret, and so can anyone with access to etcd Source 1সোর্স 1. In step 1, one command turned the base64 value back into the password, and the password was readable in etcd. To test encryption at rest, read the Secret out of etcd and look at the start of the stored value; the docs expect k8s:enc:aescbc:v1: for an aescbc setup Source 3সোর্স 3.

Ask as the identity under test, and ask for the "no" answers too. kubectl auth can-i pairs nicely with impersonation Source 9সোর্স 9. In step 2, the identity could list Pods in its own namespace, and could not delete Pods, get Secrets, or list Pods in default; a Role always sets permissions within one namespace Source 5সোর্স 5.

Read the whole rejection. With the enforce mode, a policy violation causes the pod to be rejected Source 11সোর্স 11. In step 3, one message named four violations at once, and each one is a control of the Restricted policy Source 10সোর্স 10. A Deployment is not rejected as such: enforce mode is applied only to the resulting pod objects, not to workload resources Source 11সোর্স 11, so look at the Pods.

Prove a NetworkPolicy with a request that should fail. A NetworkPolicy resource created without a controller that implements it has no effect Source 13সোর্স 13, and kind lets you install a different CNI Source 14সোর্স 14. In step 4, the same request changed from an answer to a timeout after the policy, and the label of the client decided which client was let in again.

Go down the list of checks in order. kubectl describe shows the current state and the recent events Source 15সোর্স 15, kubectl logs shows the logs of the container Source 17সোর্স 17, and --previous shows the previous instance Source 18সোর্স 18. kubectl debug helps when kubectl exec is not enough Source 16সোর্স 16. In step 5, the exit code 1 and the two lines of the previous logs named the failure that the container printed.

Check that you may debug at all. If you run kubectl debug to add an ephemeral container without the required permission, you will see an error similar to Error from server (Forbidden) Source 16সোর্স 16. When granting permission to add ephemeral containers to Pods governed by the baseline or restricted policy, the docs say to choose a matching debugging profile such as --profile=baseline or --profile=restricted with kubectl debug Source 16সোর্স 16.

বাংলা ব্যাখ্যা

যার access আছে তার মতো করে একটা Secret পড়ুন। API access আছে এমন যে কেউ একটা Secret পড়তে বা বদলাতে পারে, আর etcd-তে access আছে এমন যে কেউও পারে Source 1সোর্স 1। ধাপ ১-এ একটা command base64 মানটাকে আবার password বানিয়েছে, আর password etcd-তে পড়া গেছে। encryption at rest test করতে Secret-টা etcd থেকে পড়ুন আর stored মানের শুরুটা দেখুন; docs একটা aescbc setup-এর জন্য k8s:enc:aescbc:v1: আশা করে Source 3সোর্স 3।

test-করা identity হিসেবে জিজ্ঞেস করুন, আর "no" উত্তরগুলোও জিজ্ঞেস করুন। kubectl auth can-i impersonation-এর সাথে ভালো মানায় Source 9সোর্স 9। ধাপ ২-এ identity নিজের namespace-এ Pod list করতে পেরেছে, আর Pod delete করতে, Secret get করতে বা default-এ Pod list করতে পারেনি; একটা Role সবসময় একটা নির্দিষ্ট namespace-এর ভেতরে permission ঠিক করে Source 5সোর্স 5।

পুরো rejection পড়ুন। enforce mode-এ policy violation হলে pod reject হয় Source 11সোর্স 11। ধাপ ৩-এ একটা message একসাথে চারটা violation-এর নাম বলেছে, আর প্রতিটা Restricted policy-র একটা control Source 10সোর্স 10। একটা Deployment নিজে reject হয় না: enforce mode শুধু ফলস্বরূপ pod object-এ প্রয়োগ হয়, workload resource-এ নয় Source 11সোর্স 11, তাই Pod-গুলো দেখুন।

যে request ব্যর্থ হওয়ার কথা, তা দিয়ে একটা NetworkPolicy প্রমাণ করুন। যে controller NetworkPolicy প্রয়োগ করে, সেটা ছাড়া একটা NetworkPolicy resource তৈরি করলে তার কোনো প্রভাব পড়ে না Source 13সোর্স 13, আর kind আপনাকে অন্য একটা CNI install করতে দেয় Source 14সোর্স 14। ধাপ ৪-এ policy-র পরে একই request উত্তর থেকে time-out হয়ে গেছে, আর client-এর label ঠিক করেছে কোন client আবার ঢুকতে পেরেছে।

check-এর ক্রম ধরে নিচে নামুন। kubectl describe বর্তমান state আর সাম্প্রতিক event দেখায় Source 15সোর্স 15, kubectl logs container-এর log দেখায় Source 17সোর্স 17, আর --previous আগের instance দেখায় Source 18সোর্স 18। kubectl exec যথেষ্ট না হলে kubectl debug সাহায্য করে Source 16সোর্স 16। ধাপ ৫-এ exit code 1 আর আগের log-এর দুটো line সেই ব্যর্থতার নাম বলেছে, যা container প্রিন্ট করেছিল।

debug করার অনুমতি আছে কি না, যাচাই করুন। প্রয়োজনীয় permission ছাড়া kubectl debug দিয়ে ephemeral container যোগ করতে গেলে আপনি Error from server (Forbidden)-এর মতো একটা error দেখবেন Source 16সোর্স 16। baseline বা restricted policy-র অধীনের Pod-এ ephemeral container যোগ করার permission দেওয়ার সময় docs বলে kubectl debug-এর সাথে --profile=baseline বা --profile=restricted-এর মতো মানানসই একটা debugging profile বেছে নিতে Source 16সোর্স 16।

Common mistakes

  • Calling base64 "encrypted". Base64 encoded values are obscured, but that does NOT provide any useful level of confidentiality Source 1সোর্স 1.
  • Sharing Secret manifests. Sharing the file, or checking it in to a source repository, means the secret is available to everyone who can read the manifest Source 2সোর্স 2.
  • Forgetting who can read Secrets through a Pod. Anyone who is authorized to create a Pod in a namespace can use that access to read any Secret in that namespace Source 1সোর্স 1.
  • Trusting a NetworkPolicy that was only created. Without a controller that implements it, a NetworkPolicy resource will have no effect Source 13সোর্স 13.
  • Forgetting DNS. A default deny-all egress policy also blocks DNS traffic Source 13সোর্স 13.
  • Reading only the Deployment under a Pod Security policy. Enforce mode is not applied to workload resources, only to the resulting pod objects Source 11সোর্স 11.
  • Using kubectl exec ... sh on an image with no shell. There is no shell in such an image, and you can instead add a debugging container using kubectl debug Source 16সোর্স 16.
  • Reading the logs of a crashing container without --previous. -p, --previous prints the logs for the previous instance of the container in a pod if it exists Source 18সোর্স 18.

সহজ English

  • Calling base64 "encrypted". Base64 encoding obscures the values, but that does NOT provide any useful level of confidentiality Source 1সোর্স 1.
  • Sharing Secret manifests. Sharing the file, or checking it in to a source repository, means that everyone who can read the manifest has the secret Source 2সোর্স 2.
  • Forgetting who can read Secrets through a Pod. Anyone who is allowed to create a Pod in a namespace can use that access to read any Secret in that namespace Source 1সোর্স 1.
  • Trusting a NetworkPolicy that was only created. Without a controller that implements it, a NetworkPolicy resource has no effect Source 13সোর্স 13.
  • Forgetting DNS. A default deny-all egress policy also blocks DNS traffic Source 13সোর্স 13.
  • Reading only the Deployment under a Pod Security policy. Enforce mode is applied only to the resulting pod objects, not to workload resources Source 11সোর্স 11.
  • Using kubectl exec ... sh on an image with no shell. There is no shell in such an image, and you can instead add a debugging container using kubectl debug Source 16সোর্স 16.
  • Reading the logs of a crashing container without --previous. -p, --previous prints the logs for the previous instance of the container in a pod if it exists Source 18সোর্স 18.

বাংলা ব্যাখ্যা

  • base64-কে "encrypted" বলা। base64 encoding মানগুলো obscure করে, কিন্তু তাতে কোনো কার্যকর মাত্রার confidentiality পাওয়া যায় না Source 1সোর্স 1।
  • Secret manifest শেয়ার করা। ফাইলটা শেয়ার করলে বা source repository-তে check in করলে manifest যে কেউ পড়তে পারে, সে-ই secret পেয়ে যায় Source 2সোর্স 2।
  • Pod-এর মাধ্যমে কে Secret পড়তে পারে, তা ভুলে যাওয়া। একটা namespace-এ Pod তৈরির অনুমতি আছে এমন যে কেউ সেই access দিয়ে ওই namespace-এর যেকোনো Secret পড়তে পারে Source 1সোর্স 1।
  • শুধু তৈরি করা একটা NetworkPolicy-কে বিশ্বাস করা। যে controller NetworkPolicy প্রয়োগ করে, সেটা ছাড়া একটা NetworkPolicy resource-এর কোনো প্রভাব পড়ে না Source 13সোর্স 13।
  • DNS ভুলে যাওয়া। একটা default deny-all egress policy DNS traffic-ও আটকায় Source 13সোর্স 13।
  • Pod Security policy-র অধীনে শুধু Deployment দেখা। Enforce mode শুধু ফলস্বরূপ pod object-এ প্রয়োগ হয়, workload resource-এ নয় Source 11সোর্স 11।
  • shell নেই এমন image-এ kubectl exec ... sh ব্যবহার করা। এমন image-এ কোনো shell থাকে না, আর তার বদলে আপনি kubectl debug দিয়ে একটা debugging container যোগ করতে পারেন Source 16সোর্স 16।
  • --previous ছাড়া একটা crash-করা container-এর log পড়া। -p, --previous pod-এর container-এর আগের instance-এর log দেখায়, যদি থাকে Source 18সোর্স 18।

What a tester can check

Tutorial advice

This list is the tutorial's own advice for a tester whose app runs on Kubernetes.

  • Check whether a Secret value can be read in clear text from the API and from etcd, and whether encryption at rest is enabled.
  • For each identity of the app, check what it may do and what it may not do, with kubectl auth can-i --as=....
  • Check that a namespace with an enforce label rejects a Pod that breaks the policy, and read which violations the message names.
  • Check that a NetworkPolicy blocks a client that must be blocked and still lets in a client that must be let in.
  • For a Pod that restarts, check the restart count, the exit code, the previous logs, and the events.
  • Make a test run clean up the namespaces that it made.

সহজ English

Tutorial advice

This list is the tutorial's own advice for a tester whose app runs on Kubernetes.

  • Check whether a Secret value can be read in clear text from the API and from etcd, and whether encryption at rest is enabled.
  • For each identity of the app, check what it may do and what it may not do, with kubectl auth can-i --as=....
  • Check that a namespace with an enforce label rejects a Pod that breaks the policy, and read which violations the message names.
  • Check that a NetworkPolicy blocks a client that must be blocked and still lets in a client that must be let in.
  • For a Pod that restarts, check the restart count, the exit code, the previous logs, and the events.
  • Make a test run clean up the namespaces that it made.

বাংলা ব্যাখ্যা

Tutorial advice

এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, এমন একজন tester-এর জন্য যার app Kubernetes-এ চলে।

  • একটা Secret-এর মান API থেকে আর etcd থেকে clear text-এ পড়া যায় কি না, আর encryption at rest চালু আছে কি না, যাচাই করুন।
  • app-এর প্রতিটা identity কী করতে পারে আর কী পারে না, kubectl auth can-i --as=... দিয়ে যাচাই করুন।
  • enforce label-ওয়ালা একটা namespace policy ভাঙা Pod reject করে কি না যাচাই করুন, আর message কোন violation-এর নাম বলে তা পড়ুন।
  • একটা NetworkPolicy যে client আটকানোর কথা তাকে আটকায় আর যে client ঢোকানোর কথা তাকে ঢুকতে দেয় কি না, যাচাই করুন।
  • যে Pod restart হচ্ছে, তার restart-সংখ্যা, exit code, আগের log আর event দেখুন।
  • একটা test run যে namespace বানিয়েছে, সেগুলো পরিষ্কার করিয়ে নিন।

Key words

TermMeaning
SecretAn object that contains a small amount of sensitive data such as a password, a token, or a key
base64The encoding of the values in the data field of a Secret; it obscures them but gives no useful confidentiality
Encryption at restNot enabled by default: the API server stores plain-text representations of resources into etcd
etcdThe data store that the API server uses underneath
RBACRegulates access to resources based on the roles of individual users
Role, RoleBindingA set of permissions in one namespace, and the grant of it to subjects
ServiceAccountA non-human account that gives a distinct identity in the cluster
kubectl auth can-iChecks whether an action is allowed; --as asks as another identity
Pod Security StandardsThree policies: Privileged, Baseline, and Restricted
enforce, audit, warnWhat a policy violation does: rejects the Pod, adds an audit annotation, or shows a warning
NetworkPolicyRules for traffic at the IP address or port level; needs a network plugin that implements it
Isolated for ingressA Pod that some NetworkPolicy selects, with "Ingress" in its policyTypes
CrashLoopBackOffThe backoff delay between restarts of a container that keeps failing is in effect
kubectl logs --previousPrints the logs for the previous instance of the container, if it exists
Ephemeral containerA container added to a running Pod for troubleshooting, with kubectl debug

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

Show 3 more reelsআরও 3টি রিল দেখান
  1. [1]
    Secrets

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  2. [2]
    Good practices for Kubernetes Secrets

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  3. [3]
    Encrypting Confidential Data at Rest

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  4. [4]
    Operating etcd clusters for Kubernetes

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  5. [5]
    Using RBAC Authorization

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  6. [6]
    Service Accounts

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  7. [7]
    kubectl create role

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  8. [8]
    kubectl create rolebinding

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  9. [9]
    kubectl auth can-i

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  10. [10]
    Pod Security Standards

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  11. [11]
    Pod Security Admission

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  12. [12]
    Enforce Pod Security Standards with Namespace Labels

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  13. [13]
    Network Policies

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  14. [14]
    kind – Configuration

    kind documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  15. [15]
    Debug Pods

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  16. [16]
    Debug Running Pods

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  17. [17]
    Pod Lifecycle

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  18. [18]
    kubectl logs

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  19. [19]
    kubectl debug

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  20. [20]
    kubectl run

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  21. [21]
    kubectl create secret generic

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  22. [22]
    kubectl create serviceaccount

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  23. [23]
    kubectl create deployment

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  24. [24]
    kubectl expose

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  25. [25]
    kubectl rollout status

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  26. [26]
    kubectl wait

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  27. [27]
    kubectl Quick Reference

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  28. [28]
    Share a Cluster with Namespaces

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18

  29. [29]
    kubectl delete

    Kubernetes documentation · accessed 2026-11-18দেখা হয়েছে: 2026-11-18