콘텐츠로 이동

2025 07 19

2025-07-19

kubectl -o 출력 옵션

  • -o wide: 추가 정보까지 한 줄로 출력
  • -o yaml: 리소스를 yaml 포맷으로 출력
  • -o json: 리소스를 json 포맷으로 출력
  • -o jsonpath=: jsonpath 표현식으로 특정 필드만 출력
  • -o jsonpath='{...}': 셸 이스케이프를 피하기 위함
  • -o name: 리소스 종류와 이름만 출력

k8s rbac

참고: https://velog.io/@rockwellvinca/kubernetes-RBAC

  • 개요
    • Role-Based Access Control
    • 사용자, 그룹, 서비스 계정 (SA)에 클러스터 내의 리소스 접근을 제어하는 방법
  • Role
    • 특정 네임스페이스에 권한 부여를 정의
    • 네임스페이스 내에 수행할 수 있는 행동, 그 행동이 적용될 리소스를 지정
  • RoleBinding
    • 사용자/그룹/서비스 계정에 Role을 연결시키는 방법
    • 네임스페이스 범위 내에서만 동작
      apiVersion: rbac.authorization.k8s.io/v1
      kind: RoleBinding
      metadata:
        name: example-rolebinding
        namespace: example-namespace
      subjects:
      
      - kind: ServiceAccount
        name: example-serviceaccount
        namespace: example-namespace
      roleRef:
        kind: Role
        name: example-role
        apiGroup: rbac.authorization.k8s.io
      ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: RoleBinding
      metadata:
        name: example-rolebinding
        namespace: example-namespace
      subjects:
      
      - kind: User
        name: example-user
        apiGroup: rbac.authorization.k8s.io
      roleRef:
        kind: Role
        name: example-role
        apiGroup: rbac.authorization.k8s.io
      ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: RoleBinding
      metadata:
        name: example-rolebinding
        namespace: example-namespace
      subjects:
      
        - kind: Group
          name: example-group
          apiGroup: rbac.authorization.k8s.io
      roleRef:
        kind: Role
        name: example-role
        apiGroup: rbac.authorization.k8s.io
      
  • ClusterRole
    • 클러스터 전체에 걸쳐 권한을 정의
    • 네임스페이스 전체를 다 사용할 수 있는 권한
      • 모든 네임스페이스 수준의 리소스에 대한 권한도 부여할 수 있음.
        apiVersion: rbac.authorization.k8s.io/v1
        kind: ClusterRole
        metadata:
          name: pod-reader
        rules:
        
          - apiGroups: [""]
            resources: ["pods"]
            verbs: ["get", "list", "watch"]
        
  • ClusterRoleBinding
    • 사용자/그룹/서비스 계정에 ClusterRole을 연결
    • namespace를 지정하는 부분이 별도로 없음!