[root@kube ~]# hostnamectl set-hostname master
[root@master ~]# vi /etc/hosts
192.168.x.x master
[root@master ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@master ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@master ~]# yum -y install docker-ce
[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl disable firewalld
[root@master ~]# sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
[root@master ~]# setenforce 0
[root@master ~]# getenforce
Permissive
default값이 0 이다. bridge 네트워크 송수신 패킷이 iptable을 우회함
그래서 1로 활성화 시킴 즉, kubernetes에서는 iptable을 사용할 수 있게 enable해주는것
[root@master ~]# modprobe br_netfilter
[root@master sysctl.d]# ll /proc/sys/net/
total 0
dr-xr-xr-x. 1 root root 0 May 22 10:29 bridge
[root@master ~]# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
[root@master ~]# modprobe br_netfilter
또는
[root@master ~]# vi /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
[root@master ~]# sysctl --system
확인 # sysctl -a | grep iptables
[root@master sysctl.d]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@master sysctl.d]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
kubelet 동작위해 swap off 시킴
[root@master sysctl.d]# swapoff -a
[root@master sysctl.d]# vi /etc/fstab //아래 주석처리
#/dev/mapper/centos-swap swap swap defaults 0 0
k8s repo 추가
[root@master sysctl.d]# vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gp
docker, kubelet 데몬 활성화
[root@master sysctl.d]# systemctl start docker && systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@master sysctl.d]# systemctl start kubelet && systemctl enable kubelet
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
kube관련 설치
[root@master sysctl.d]# yum -y install kubelet kubeadm kubectl --disableexcludes=kubernetes
쿠버네티스 클러스터 초기화
[root@master ~]# kubeadm init --apiserver-advertise-address=192.168.200.150 --pod-network-cidr=10.244.0.0/16
[root@master ~]# kubeadm init --apiserver-advertise-address=192.168.200.150 --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.21.1
[preflight] Running pre-flight checks
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[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'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master] and IPs [10.96.0.1 192.168.200.150]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost master] and IPs [192.168.200.150 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master] and IPs [192.168.200.150 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[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"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[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
[apiclient] All control plane components are healthy after 33.508927 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.21" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node master as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: whrnkx.ew8481lg7fvn7ypx
[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
[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/
Then you can join any number of worker nodes by running the following on each as root:
//아래 명령어는 worker 노드들 조인할때 사용
kubeadm join 192.168.200.150:6443 --token whrnkx.ew8481lg7fvn7ypx \
--discovery-token-ca-cert-hash sha256:68ed03cfcc60e22e58dbb5587e9961ebf636087ff78998bc88c98cc56f100c85
따로 복사 그룹 변경
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]# chown $(id -u):$(id -g) $HOME/.kube/config
[root@master ~]# ls -als ~/.kube/config
8 -rw-------. 1 root root 5599 May 22 10:46 /root/.kube/config
cni는 플라넬 사용
[root@master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Warning: policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created
확인
[root@master ~]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-558bd4d5db-mxj4t 1/1 Running 0 8m7s
kube-system coredns-558bd4d5db-w9s4w 1/1 Running 0 8m7s
kube-system etcd-master 1/1 Running 0 8m13s
kube-system kube-apiserver-master 1/1 Running 0 8m13s
kube-system kube-controller-manager-master 1/1 Running 0 8m13s
kube-system kube-flannel-ds-2xtzc 1/1 Running 0 44s
kube-system kube-proxy-k2v27 1/1 Running 0 8m8s
kube-system kube-scheduler-master 1/1 Running 0 8m13s
[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 8m29s v1.21.1
worker 노드에 붙일려면 ..
아래 명령어 입력
#kubeadm join 192.168.200.150:6443 --token whrnkx.ew8481lg7fvn7ypx \
--discovery-token-ca-cert-hash sha256:68ed03cfcc60e22e58dbb5587e9961ebf636087ff78998bc88c98cc56f100c85
참고: https://gruuuuu.github.io/cloud/k8s-install/
https://likefree.tistory.com/12
'kubernetes' 카테고리의 다른 글
컨테이너 인프라환경 구축을 위한 쿠버네티스/도커 -2 (0) | 2021.08.31 |
---|---|
컨테이너 인프라환경 구축을 위한 쿠버네티스/도커 -1 (0) | 2021.08.31 |
kubernetes - nagios 설치 (0) | 2021.05.24 |
kubernetes - naigos pod 설치 (0) | 2021.05.22 |
kubernetes-centos7 minikube 설치 (0) | 2021.05.21 |