단일 노드 구축
- VM 제원
- minikube version: v1.23.2
- kubectl version: v1.22.2
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:32:41Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
Minikube 설치
- Single Node 구축: Master Node + Worker Node
$ yum update -y
$ hostnamectl set-hostname minikube
$ curl -fsSL https://get.docker.com/ | sudo sh
$ systemctl enable --now docker
$ yum install -y conntrack git
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.23.2/minikube-linux-amd64 && chmod +x minikube
$ mkdir -p /usr/local/bin/
$ install minikube /usr/local/bin/
$ minikube version
$ minikube start --driver=none
$ minikube status
위치를 옮김
$ sudo mv /root/.kube /root/.minikube $HOME
소유권 변경, 자격증명 관련 권한 존재
$ sudo chown -R $USER $HOME/.kube $HOME/.minikube
kubectl 설치
kubectl <CMD>
=> 마스터 노드에 요청
$ curl -LO https://dl.k8s.io/release/v1.22.2/bin/linux/amd64/kubectl
$ install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
$ yum install bash-completion -y
$ source <(kubectl completion bash)
$ echo "source <(kubectl completion bash)" >> ~/.bashrc
$ exit
$ kubectl version
$ kubectl get node
멀티 노드 구축
All Node 설정
- 가상머신 생성
- 설정
$ cat <<EOF >> /etc/hosts
192.168.2.125 master1
192.168.2.126 worker1
192.168.2.127 worker2
EOF
$ hostnamectl set-hostname master
$ curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
$ sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/docker-ce.repo
$ yum --enablerepo=docker-ce-stable -y install docker-ce-19.03.15-3.el7
$ mkdir /etc/docker
$ cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
$ systemctl enable --now docker
$ systemctl daemon-reload
$ systemctl restart docker
$ systemctl disable --now firewalld
$ setenforce 0
$ sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
$ swapoff -a
$ sed -i '/ swap / s/^/#/' /etc/fstab
$ cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
$ sysctl --system
$ reboot
Kubeadm 설치
Multi Node: Master Node, Worker Node
$ cat <<'EOF' > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
$ yum -y install kubeadm-1.19.16-0 kubelet-1.19.16-0 kubectl-1.19.16-0 --disableexcludes=kubernetes
$ systemctl enable kubelet
$ poweroff
--- Master ---
$ kubeadm init --apiserver-advertise-address=192.168.2.125 --pod-network-cidr=10.244.0.0/16
$ mkdir -p $HOME/.kube
$ cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
$ kubectl get pods --all-namespaces
$ source <(kubectl completion bash)
$ echo "source <(kubectl completion bash)" >> ~/.bashrc
$ exit
--- Node ---
$ kubeadm join 192.168.2.125:6443 --token dvheus.2rzrpezo0ndia21q \
--discovery-token-ca-cert-hash sha256:162b3363e8952d01bfa1a96193236b756ef0c49ea7318747e3af4b81d80af297
$ kubectl get nodes
기본 사용법
$ mkdir workspace && cd $_
$ kubectl [명령어] [유형] [자원 이름] [옵션]
$ kubectl get node
$ kubectl run nginx-pod --image=nginx
$ kubectl expose pod nginx-pod --name clusterip --type=ClusterIP --port 80
$ kubectl expose pod nginx-pod --name nodeport --type=NodePort --port 80
$ kubectl expose pod nginx-pod --name loadbalancer --type=LoadBalancer --external-ip 192.168.0.192 --port 80
$ kubectl get pod
$ kubectl get service
$ kubectl exec -it nginx-pod -- bash
$ kubectl get all
$ kubectl delete svc --all
$ kubectl delete pod nginx-pod
$ kubectl delete pod,svc --all