쿠버네티스의 설치 과정을 요약해보면
1. 초기화
2. 환경 점검
3. 인증키 발급
4. 환경 설정 구성
5. 쿠버네티스 마스터 노드의 컴포넌트 배포
6. 네트워크 운영에 필요한 CNI ( CALICO, FLANNEL, WEAVE 등 ) 설치
// 마스터 노드에는 칼리코 컨트롤러, IPAM 플러그인, CALICOCTL, CONFD가 설정되고 칼리코 설정정보가 ETCD에 저장
7. 워커노드 조인 시 해당 노드에 CALICO POD 배포 ( Bird, felix )
kubeadm을 사용해야하는 이유
- kubelet에서 API 서버 인증서를 인증시 사용하는 클라이언트 인증서
- API 서버가 kubelet과 통신하기 위한 kubelet 서버 인증서
- API 서버 엔드포인트를 위한 서버 인증서
- API 서버에 클러스터 관리자 인증을 위한 클라이언트 인증서
- API 서버에서 kubelet과 통신을 위한 클라이언트 인증서
- API 서버에서 etcd 간의 통신을 위한 클라이언트 인증서
- 컨트롤러 매니저와 API 서버 간의 통신을 위한 클라이언트 인증서/kubeconfig
- 스케줄러와 API 서버간 통신을 위한 클라이언트 인증서/kubeconfig
- front-proxy를 위한 클라이언트와 서버 인증서
쿠버네티스를 구성하기 위한 인증서와 인증키는 이렇게 많다. 이런 것을 보다 쉽게 관리하고 교환하는 과정을 kubeadm api를 사용하여 구성이 가능하다.
[init] Using Kubernetes version: v1.24.5
==================================== 환경 점검 ====================================
[preflight] Running pre-flight checks
> 체크 시작
[preflight] Pulling images required for setting up a Kubernetes cluster
> 쿠버네티스 이미지 다운
[preflight] This might take a minute or two, depending on the speed of your internet connection
> 인터넷 점검
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
> 쿠버 adm config 이미지 다운
================================================================================
==================================== 인증키 발급 ====================================
[certs] Using certificateDir folder "/etc/kubernetes/pki"
> 쿠버네티스 인증 폴더로 "/etc/kubernetes/pki" 사용함
[certs] Generating "ca" certificate and key
> 쿠버네티스 ca 인증서, 키 생성
[certs] Generating "apiserver" certificate and key
> 쿠버네티스 apiserver 인증서, 키 생성
[certs] apiserver serving cert is signed for DNS names [k8s-master-01 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local lb-01] and IPs [10.96.0.1 10.0.2.111]
> 쿠버네티스 config의 pod subnet을 바탕으로 ip 대역 생성
[certs] Generating "apiserver-kubelet-client" certificate and key
> 쿠버네티스 apiserver-kubelet-client 인증서, 키 생성
[certs] Generating "front-proxy-ca" certificate and key
> 쿠버네티스 front-proxy-ca 인증서, 키 생성
[certs] Generating "front-proxy-client" certificate and key
> 쿠버네티스 front-proxy-client 인증서, 키 생성
--- 외부 etcd 구성이므로 내부 etcd 구성은 스킵함. ---
[certs] External etcd mode: Skipping etcd/ca certificate authority generation
[certs] External etcd mode: Skipping etcd/server certificate generation
[certs] External etcd mode: Skipping etcd/peer certificate generation
[certs] External etcd mode: Skipping etcd/healthcheck-client certificate generation
[certs] External etcd mode: Skipping apiserver-etcd-client certificate generation
----------- 여기 까지 스킵 ------------
[certs] Generating "sa" key and public key
> sa : service account
- 서비스 어카운트는 클러스터 네임스페이스를 체계적으로 권한을 관리하기 위한 오브젝트
- 네임 스페이스에 속하는 오브젝트 << RBAC
================================================================================
==================================== 환경 구성 ====================================
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
W1006 20:01:36.116957 9853 endpoint.go:57] [endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Writing "admin.conf" kubeconfig file
W1006 20:01:36.358279 9853 endpoint.go:57] [endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Writing "kubelet.conf" kubeconfig file
W1006 20:01:36.414213 9853 endpoint.go:57] [endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
W1006 20:01:36.554039 9853 endpoint.go:57] [endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Writing "scheduler.conf" kubeconfig file
======================================================================================
========================= kubelet이 동작하며 각종 static pod를 생성함 ==========================
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
// 여기서 static Pod란?
// API 서버 없이 특정 노드의 kubelet 데몬에 의해 관리되는 파드. 이 스태틱 파드의 정의는 서버 내 특정 디렉토리에
// yaml 형태로 존재한다.
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
// 각종 static pod가 올라오기를 기다림. static pod의 yaml은 "/etc/kubernetes/manifests" 여기 있음
[apiclient] All control plane components are healthy after 5.022631 seconds
======================================================================================
====================== 설정 파일들이 CONFIG MAP에 저장됨. ===========================
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
> 컨피그맵에 Kubelet에 대한 정보가 저장됨.
[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
[upload-certs] Using certificate key:
f2d8a37cf83d092c1afa0b7202102760b15df621bd6de08c0afbfc4b3277f443
> 토큰 발급
================================== 컨트롤 플레인으로 선정됨 ==================================
[mark-control-plane] Marking the node k8s-master-01 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node k8s-master-01 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule node-role.kubernetes.io/control-plane:NoSchedule]
=====================================================================================
================================= 시스템 관리를 위한 토큰, RBAC을 구성함 ===================
[bootstrap-token] Using token: guappu.kqhjxk9k8xahnlz3
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
=========================================================================================
============================ 추가적인 구성 적용 ======================================
[addons] Applied essential addon: CoreDNS
W1006 20:01:45.971582 9853 endpoint.go:57] [endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[addons] Applied essential addon: kube-proxy
============================================================================
Your Kubernetes control-plane 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
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
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 the control-plane node running the following command on each as root:
kubeadm join lb-01:26443 --token 8mclb9.swwwp1amq1twk6qq \
--discovery-token-ca-cert-hash sha256:381d2905944b8d0617b1f5ced51fa2c94732a014107203cc0d13632ebf26e5ac \
--control-plane --certificate-key 696e4f7c9b1d5e4f23007a516d457c48351b3382e53da988b6ec0a84ed651a16
Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join lb-01:26443 --token 8mclb9.swwwp1amq1twk6qq \
--discovery-token-ca-cert-hash sha256:381d2905944b8d0617b1f5ced51fa2c94732a014107203cc0d13632ebf26e5ac
=================================================================================
이제 쿠버네티스 환경 구성을 위한 Kubeadm config파일에 대해서 알아보자
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration // 클러스터 구성
// ClusterConfiguration : etcd, kube-apiserver, kube-scheduler, kube-controller-manager 구성함
kubernetesVersion: "1.24.5" // 버전
controlPlaneEndpoint: "lb-01:26443"
// 로드밸런서 기반의 control plane을 위한 lb ip:port
// lb-01에 haproxy 기반의 master node들을 로드밸런싱을 적용함
etcd:
external:
endpoints:
- https://etcd-01:2379 // 외부 etcd 주소 1
- https://etcd-02:2379 // 외부 etcd 주소 2
- https://etcd-03:2379 // 외부 etcd 주소 3
caFile: /etc/kubernetes/pki/etcd/ca.crt
certFile: /etc/kubernetes/pki/apiserver-etcd-client.crt
keyFile: /etc/kubernetes/pki/apiserver-etcd-client.key
- ca.crt : 쿠버네티스 root CA 인증서, 여러 다른 인증서를 이를 기반으로 발급
- apiserver-etcd-client.crt : apiserver가 etcd와 연결하기 위해 사용하는 키
- apiserver-etcd-client.key : apiserver-etcd-client.crt와 대응되는 비밀 키
networking:
podSubnet: 10.96.0.0/12
// podSubnet
: 파드의 cidr를 구성함
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
// kubeadm init의 런타임에 적용되는 정보이다.
localAPIEndpoint:
// apiserver의 endpoint를 기입.
// ClusterConfiguration 에도 비슷한 정보가 있지만, 해당 정보랑은 다르다.
// 쿠버네티스 클러스터를 구성하게되면, api서버를 자동으로 찾게되는데, 찾는게 불가능하면
// 아래의 ip:port로 api server를 설정한다.
advertiseAddress: 192.168.56.111
bindPort: 6443
아래 독스 참조
https://kubernetes.io/docs/reference/config-api/kubeadm-config.v1beta3/
이외의 쿠버네티스 인증서, 인증키 목록
- apiserver.crt : etcd를 제외한 k8s 컴포넌트들이 apiserver와 통신하기위한 기반
- apiserver.key : apiserver.crt와 대응되는 비밀 키
- apiserver-etcd-client.crt : apiserver가 etcd와 연결하기 위해 사용하는 키
- apiserver-etcd-client.key : apiserver-etcd-client.crt와 대응되는 비밀 키
- apiserver-kubelet-client.crt : apiserver가 kubelet과 연결하기 위해 사용하는 키
- apiserver-kubelet-client.key : apiserver-kubelet-client.crt와 대응되는 비밀 키
- ca.crt : 쿠버네티스 root CA 인증서, 여러 다른 인증서를 이를 기반으로 발급
- ca.key : ca.crt에 대응되는 비밀 키
- front-proxy-ca.crt : kube-proxy에서 API 서버 확장을 할 때만 kube-proxy쪽에 필요한 것, EX) 사용자 정의 확장 api 서버를 구성할 경우
- front-proxy-ca.key : front-proxy-ca.crt에 대응되는 비밀 키
- front-proxy-client.crt :
- front-proxy-client.key : front-proxy-client.crt와 대응되는 비밀 키
- sa.key : k8s의 Service Account Token을 암/복호화 하는데 사용
- sa.pub : k8s의 Service Account Token을 암/복호화 하는데 사용
- etcd/ca.crt : etcd CA 인증서
- etcd/ca.key : etcd/ca.crt에 대응되는 비밀 키
- etcd/healthcheck-client.crt
- etcd/healthcheck-client.key
- etcd/peer.crt : etcd cluster내의 etcd server간 통신에 사용
- etcd/peer.key : etcd/peer.crt에 대응하는 비밀키
- etcd/server.crt : etcd 서버에 대한 certificate 수행, kube-apiserver 또는 etcdctl에서 사용
- etcd/server.key : etcd/server.crt에 대응되는 비밀 키
'쿠버네티스,도커' 카테고리의 다른 글
쿠버네티스 정리중 (0) | 2022.10.10 |
---|---|
쿠버네티스 kubeadm을 사용한 설치 시작부터 끝까지. (2) | 2022.10.08 |
calico 동작 (0) | 2022.10.03 |
가상화, TYPE1, TYPE2 // 반가상화, 전가상화 (0) | 2022.09.28 |
FQDN(Fully Qualified Domain Name) (0) | 2022.09.21 |