[kubernetes]クラスタの作成


kubernetes sequence
(docker설치 생략) (master worker 둘다)
sudo passwd ubuntu
systemctl start docker
systemctl enable docker

sudo apt-get update&&sudo apt-get upgrade
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
> br_netfilter
> EOF
br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
sudo sysctl --system

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-get update&&sudo apt-get upgrade


(master)
sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=**private주소** --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


(worker)
root에 접속하여
export KUBECONFIG=/etc/kubernetes/admin.conf


(master)
kubectl get nodes
sudo kubectl get nodes
sudo kubectl get pods --all-namespaces
kubectl apply -f https://k8s.io/examples/service/access/hello-application.yaml

kubectl get deployments hello-world
kubectl describe deployments hello-world

$kubectl get replicasets
$kubectl describe replicasets

$kubectl expose deployment hello-world --type=NodePort --name=example-service
service/example-service exposed

$kubectl describe services example-service
$kubectl get pods --selector="run=load-balancer-example" --output=wide

마지막
curl http://worker의 pub 주소:위에뜬 포트번호