반응형

Cluster

- Master, Node 2가지 타입의 리소스가 존재한다.

- Master : cluster를 관리한다. 

- Node : Worker Machine 으로 제공되는 VM 또는 물리적 컴퓨터이다. 

            각각의 Node 는 Node 를 관리하고 Kubernetes master와 커뮤니케이션을 할수 있는 Kubelet 이라는 agent 를 가지고 있다. 

            Node 는 master 가 노출시켜놓은 Kubernetes API 를 사용해서 통신을 한다. 





https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/

Pod

- Deployment 를 생성하게 되면 Deployment는 Pod 를 생성하고 그 안에 Container 를 넣는다. 

- Pod 는 1개 이상의 어플리케이션 컨테이너와 그 컨테이너들이 공유하는 리소스의 그룹이다. 

- 공유 리소스는 volume, clusterIP 가 있다. 

- Pod 안에 있는 Container 들은 IP 와 port 를 공유한다. 

- Pod 는 Unique IP address 를 가지고 있다.


https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/



Service

- Pod 의 논리적 집합과  그것을 접근 할수 있는 정책을 정의 해준다. 

- Service 가 설정하는 Pod 의 논리적 집합은 LabelSelector 로 정의 한다. 

- 다음과 같은 type 이 존재한다. 


 type

 내용 

 ClusterIP 

 default 이다. cluster 의 internal IP 만 노출 시키기 때문에 cluster 내부에서만 접근 가능하다. 

 NodePort 

 각각의 NodeIP 에 서비스를 노출시킨다. NodePort 서비스가 라우팅 할 ClusterIP 서비스가 자동으로 생성된다. 클러스터 외부에서 <NodeIP>:<NodePort> 로 접근 가능하다. 

 LoadBalancer 

 external IP 를 생성하여 클러스터 외부에서 접근 가능하게 해준다. ClusterIP 와 NodePort는 자동으로 생성된다.




https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/

728x90
반응형
반응형

1. RBAC Authorization


개개인의 Role  의해서 network resource  access 할수 있도록 허용한다.

RBAC  rbac.authorization.k8s.io API 그룹을 사용한다.

RBAC  사용하기 위해서는 apiserver start 시에 --authorization-mode=RBAC 또는 /etc/kubernetes/manifests/kube-apiserver.yaml 파일에 kube-apiserver 항목에 --authorization-mode=RBAC  설정해주면 된다.


2. Role & ClusterRole


- Role  단일한 namespace 있는 resource 에 대한 권한을 정의한다.

role.yaml

1
2
3
4
5
6
7
8
9
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
cs
apiGroups & resources : 어떤 Resource 대한 Rule 인지를 정의한다.

Verbs : 어떤 operation  할지 정의한다.


- Cluster Role  모든 namespace  대한 권한을 정의한다. 

clusterrole.yaml

1
2
3
4
5
6
7
8
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: secret-reader
rules:
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["get", "watch", "list"]
cs

Role 정의와 동일하지만 metadata  namespace 항목만 빠져있다.


3. RoleBinding & ClusterRoleBinding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
RoleBinding
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: read-pods
  namespace: default
subjects:
- kind: Group
  name: group1
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: read-secrets-global
subjects:
- kind: Group
  name: group12
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: secret-reader
  apiGroup: rbac.authorization.k8s.io
cs


Binding을 통해서 각각의 group 에 role 과 clusterrole 을 바인딩을 했다. role 은 group1, clusterrole 은 group2 에 바인딩을 했다. 


이렇게 바인딩이 끝나면 Group 에 따라서 호출할 수 있는 API 가 달라지게 된다. 



728x90
반응형
반응형

현재 AWS  EC2 에 올라가 있는 ubuntu 에 kubernetes를 설치해 보았다. 

그런데 설치를 하다보니 프리티어로 받은 t2.micro 가지고는 너무 성능이 느렸다. 거의 접속도 못할 지경에 이르렀다. 그래서 어차피 설치하고 지울거니깐 t2.large로 올렸다.


설치 전에 Docker 가 먼저 설치 되어 있어야 한다.

(Docker 가 설치 안되어 있다면 https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository 여기 참고하거나 아래 링크 에도 내용은 나와있다.)


https://kubernetes.io/docs/setup/independent/install-kubeadm/


여기에 들어가보면 친절하게 설치 하는 방법을 찾을 수 있다.

내용을 살펴보면 Docker 설치도 포함하고 있어서 Docker 가 설치되어 있지 않다면 그대로 따라 하면 된다.


그리고 나는 Ubuntu 에 설치를 하니 아래와 같이 명령어를 실행 했다. 혹시 명령어 실행중 permission 에러가 나면 sudo 붙이고 실행 하면 된다.

apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

이렇게 하면 kubelet, kubeadm, kubectl 이 설치가 된다.


https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/


그 다음 스텝으로 위 링크로 들어가서 클러스터를 생성 하면 된다.


여기 나와 있는 내용중에 보면 사양이 나와있다. 

  • One or more machines running a deb/rpm-compatible OS, for example Ubuntu or CentOS
  • 2 GB or more of RAM per machine. Any less leaves little room for your apps.
  • 2 CPUs or more on the master
  • Full network connectivity among all machines in the cluster. A public or private network is fine.

최소 사양이다. 이러니 t2.micro 로는 역부족이었다.

kubeadm init <args> 

이렇게 명령어를 날리면 뭔가 내용이 올라오면서 설치가 된다. args는 다양하게 있으나 나는 우선 필요가 없어서 안 넣었다. 설치가 완료되면 아래와 같은 내용들이 나온다. (ip랑 port, 토큰 부분은 ㅌㅌㅌ로 처리했다.)


Your Kubernetes master has initialized successfully!


To start using your cluster, you need to run the following as a regular user:


  mkdir -p $HOME/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config


You should now deploy a pod network to the cluster.

Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

  https://kubernetes.io/docs/concepts/cluster-administration/addons/


You can now join any number of machines by running the following on each node

as root:


  kubeadm join <ip>:<port> --token ㅌㅌㅌㅌㅌㅌㅌㅌ --discovery-token-ca-cert-hash sha256:ㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌ


잘 읽어보면 cluster 시작하려면 .kube에 config 파일을 만들라는 내용이 있다. 아주 편리하게 저 내용을 그대로 복사해서 붙여넣으면 된다. 그리고 아래 join에 나오는 내용은 잘 복사해서 저장해두자.


이렇게 하고 "kubectl get pods --all-namespaces" 라고 치면 아래와 비슷하게 나온다. 


NAMESPACE     NAME                                       READY     STATUS    RESTARTS   AGE

kube-system   coredns-78fcdf6894-86s7n                   0/1       Pending   0          7m

kube-system   coredns-78fcdf6894-ngk7x                   0/1       Pending   0          7m

kube-system   etcd-ip-172-31-22-134                      1/1       Running   0          7m

kube-system   kube-apiserver-ip-172-31-22-134            1/1       Running   0          7m

kube-system   kube-controller-manager-ip-172-31-22-134   1/1       Running   0          6m

kube-system   kube-proxy-46x54                           1/1       Running   0          7m

kube-system   kube-scheduler-ip-172-31-22-134            1/1       Running   0          6m


그리고 위에도 써있듯이 cluster에 network를 배포해야 한다. 

위 링크(https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#pod-network 또는 https://kubernetes.io/docs/concepts/cluster-administration/addons/) 따라가보면 종류별로 방법이 있다. 설치하고 나서 다음과 같이 확인 해보면 된다.


 kubectl get nodes

NAME               STATUS    ROLES     AGE       VERSION

ip-111-11-11-111   Ready     master    32m       v1.11.2


아직 node 를 추가 못해봤는데 다음에는 node 도 따로 추가해봐야겠다.


728x90
반응형

+ Recent posts