Is it possible to create a serviceAccount based on user and password just like how a secret object can be created from user and password with --from-literal==. I mean not using --from-literal but with any other way
If I have to create a serviceAccount to allow only reading (get) the resources but not allowed to write/modify any resource (e.g. cant create a Pod or modify a deployment etc), how it can be achieved. Does it require RBAC (i.e. role creation for SA to only have read option). Any example for this.
When we create a serviceAccount and assign it to a Pod, how does the Pod gets authenticated by kubeapi server. How does kubeapi server know that a specific Serviceaccount is only applicable for a specific Pod only. Is there any configuration change required in kubeapi server for allowing authentication using serviceAccount
Similarly, when Pod1 communicates with Pod2, if pod1 uses serviceAccount for authentication, how does Pod2 authenticate the Pod1. Does it require any special configuration in Pod2 and how does Pod2 know that Pod1 has to be authenticated by means of serviceAccount only and how does Pod2 know that a “specific” serviceAccount is to be used by Pod1.
No, secret and serviceaccount are different, serviceaccount is used for no human authentication like when pod needs to do some request on k8s API and secret is used to store sensitive information like token, password, and username. For kubernetes 1.24+ after create serviceaccount you need to explicitaly create a secret to store the token.
kubectl create sa foosa
kubectl get sa foosa
You need now to create a secret type kubernetes.io/service-account-token and assign it to the serviceaccount
No need to do anything on APIs side, on each request the pod sends the token for authentication and the APIs can verify if the token is valid and if we apply RBAC policy on it
To test your serviceaccount :