Followers

Kubernetes :- Service Account, Cluster Role, Cluster role Binding

Challenge: You have been asked to create a new ClusterRole for a deployment pipeline and bind it to a specific ServiceAccount scoped to a sp...


Challenge:

You have been asked to create a new ClusterRole for a deployment pipeline and bind it to a specific ServiceAccount scoped to a specific namespace.

Task :

Create a new ClusterRole named deployment-clusterrole, which only allows to create the following resource types:
1. Deployment
2.  Stateful Set
3.  DaemonSet
Create a new ServiceAccount named cicd-token in the existing namespace app-team1.
Bind the new ClusterRole deployment-clusterrole to the new ServiceAccount cicd-token, limited to the namespace app-team1.



Solution:

Step 1: Create a namespace app-team1 
            
            kubectl create ns app-team1

Step 2: Create clusterrole deployment-clusterrole with verb create for        Deployment,StatefulSet,DaemonSet resources

    kubectl create clusterrole deployment-clusterrole --verb=create --  resource=Deployment,StatefulSet,DaemonSet -n app-team1 

   Verify ClusterRole is created:

    kubectl get clusterrole deployment-clusterrole -n app-team1 

    kubectl describe clusterrole deployment-clusterrole -n app-team1 

Step 3: Create a service account cicd-token

          kubectl create sa cicd-token -n app-team1

         Verify service account is created:

          kubectl get sa -n app-team1

Step 4: Create a ClusterRoleBinding to bind sa with clusterrole

kubectl create clusterrolebinding deployment-clusterrolebinding --clusterrole=deployment-clusterrole --serviceaccount=app-team1:cicd-token -n app-team1

   Verify Clusterrolebidning is created

   kubectl get clusterrolebinding -n app-team1

Step 5: Verify the sa has the authorization to create deployment

kubectl auth can-i get deployment --as=system:serviceaccount:app-team1:cicd-token -n app-team1

It should return yes






         

COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Kubernetes :- Service Account, Cluster Role, Cluster role Binding
Kubernetes :- Service Account, Cluster Role, Cluster role Binding
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4TP6k4fzwdhSCW1xg3qPMCG-UuEdYk5FDu_FBfta1Wj1o_kN-lc-X6IBM7JIS-YHhnV641eA_iMPrI-d6_LaSGTinyB-F3kAw0YCQN5LYtLkurpusUxVIAysM4bMV75B6k1ej5qVU6B3d2S8IbfiWQ9DvWgLHPC3xICXKTeuagkWiVEwxYK_AqWj7xoo/s320/serviceacc.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4TP6k4fzwdhSCW1xg3qPMCG-UuEdYk5FDu_FBfta1Wj1o_kN-lc-X6IBM7JIS-YHhnV641eA_iMPrI-d6_LaSGTinyB-F3kAw0YCQN5LYtLkurpusUxVIAysM4bMV75B6k1ej5qVU6B3d2S8IbfiWQ9DvWgLHPC3xICXKTeuagkWiVEwxYK_AqWj7xoo/s72-c/serviceacc.jpg
DevOpsWorld
https://www.devopsworld.co.in/2024/02/kubernetes-service-account-cluster-role.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2024/02/kubernetes-service-account-cluster-role.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content