kakao Cloud school 2기 D+42

LEE EUI JOO·2023년 1월 9일
0

K8S

목록 보기
2/17

1. Kubernetes


  • 가상머신 스펙

  1. 이미지 : Ubuntu
  2. 램 : 4 GB
  3. 코어 : 2
  4. 프로세서 : 2
  5. ssh 연결을 위해 계정 업데이트 필요
  • 만든 가상머신을 full clone 하여 master VM, worker1, worker2 생성 (ubuntu 기반)


  • 호스트 네임 변경

hostnamectl set-hostname <변경할 호스트 네임>
vi /etc/netplan/00-installer-config.yml

master : 211.183.3.100
hostname : master

worker1 : 211.183.3.110
hostname : worker1

worker2 : 211.183.3.120
hostname : worker2


모든 노드에 명령어 입력

각 노드에 도커 설치

도커 재시작 및 실행(enable)


CRI 도커 플러그인 설치

docker를 CRI(Container Runtime Interface)로 사용하기 위해 docker를 설치(현재 k8s는 공식적으로 docker를 지원하지 않기때문에 cri-dockerd 설치가 필요.)

1.14 미만의 k8s를 설치하는것도 한가지 방법이다.

git clone https://github.com/Mirantis/cri-dockerd.git
wget https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x ./installer_linux
./installer_linux
source ~/.bash_profile
cd cri-dockerd
mkdir bin
go build -o bin/cri-dockerd
mkdir -p /usr/local/bin
install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
cp -a packaging/systemd/* /etc/systemd/system
sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
systemctl daemon-reload
systemctl enable cri-docker.service
systemctl enable --now cri-docker.socket
sudo systemctl restart docker && sudo systemctl restart cri-docker
sudo systemctl status cri-docker.socket --no-pager


Docker Cgroup 변경.

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

sudo systemctl restart docker && sudo systemctl restart cri-docker


Kernel Forwarding , kube-proxy(= 파드의 통신, 오버레이 네트워크를 담당) 설정.

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF


iptable이 오버레이 네트워크의 트래픽을 허용하도록 설정.

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

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


버전 확인

kubectl version --short


해당 버전으로 고정

sudo apt-mark hold kubelet kubeadm kubectl


  • Only Master Node

sudo kubeadm config images pull --cri-socket unix:///run/cri-dockerd.sock

sudo kubeadm init --pod-network-cidr=10.10.0.0/16 --apiserver-advertise-address=211.183.3.100 --cri-socket /var/run/cri-dockerd.sock

  • Only worker Node

kubeadm join 211.183.3.100:6443 --token sgxslr.euy1fukqiriwa9ll \
--discovery-token-ca-cert-hash <여러분의 토큰> --cri-socket unix:///run/cri-dockerd.sock


마스터에서 발행된 토큰 뒤에 --cri-socket unix:///run/cri-dockerd.sock 를 붙여준다.

  • Only Master Node

mkdir -p HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):(id -g) $HOME/.kube/config


CNI (Container Network Interface) - 컨테이너 네트워크를 구성하기 위한 플러그인

weavenet, calico 등의 오픈소스 플러그인이 존재하는데, calico 대신 CNI를 사용할 것이다

curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O

#calico 다운로드

sed -i -e 's?192.168.0.0/16?10.10.0.0/16?g' calico.yaml


우리는 아까 파드 네트워크를 10.10.0.0/16으로 변경했기때문에 CNI의 설정도 똑같이 변경해준다.

kubectl apply -f calico.yaml


master node history

 5  sudo swapoff /swap.img
 6  sudo sed -i -e '/swap.img/d' /etc/fstab
 7  curl -fsSL https://get.docker.com -o get-docker.sh
 8  sudo sh get-docker.sh
 9  sudo systemctl restart docker
 10  sudo systemctl enable docker
 11  clear
 12  git clone https://github.com/Mirantis/cri-dockerd.git
 13  wget https://storage.googleapis.com/golang/getgo/installer_linux
 14  chmod +x ./installer_linux
 15  ./installer_linux
 16  source ~/.bash_profile
 17  cd cri-dockerd
 18  mkdir bin
 19  go build -o bin/cri-dockerd
 20  mkdir -p /usr/local/bin
 21  install -o root -g root -m 0755 bin/cri-dockerd
 22  mkdir -p /usr/local/bin
 23  install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
 24  cp -a packaging/systemd/* /etc/systemd/system
 25  sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
 26  systemctl daemon-reload
 27  systemctl enable cri-docker.service
 28  systemctl enable --now cri-docker.socket
 29  sudo systemctl restart docker && sudo systemctl restart cri-docker
 30  sudo systemctl status cri-docker.socket --no-pager 
 31  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

   32  sudo systemctl restart docker && sudo systemctl restart cri-docker
   33  cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

   34  cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

 35  sudo apt-get update
 36  sudo apt-get install -y apt-transport-https ca-certificates curl
 37  sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg
 38  sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg 
 39  sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
 40  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
 41  history
 42  clear
 43  sudo apt-get update
 44  sudo apt-get install -y kubelet kubeadm kubectl
 45  kubectl version --short
 46  sudo apt-mark hold kubelet kubeadm kubectl
 47  sudo kubeadm config images pull --cri-socket unix:///run/cri-dockerd.sock
 48  sudo kubeadm init --pod-network-cidr=10.10.0.0/16 --apiserver-advertise-address=211.183.3.100 --cri-socket /var/run/cri-dockerd.sock
 49  mkdir -p $HOME/.kube
 50  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 51  sudo chown $(id -u):$(id -g) $HOME/.kube/config
 52  vi /etc/kubernetes/admin.conf 
 53  kubectl get node
 54  curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O
 55  sed -i -e 's?192.168.0.0/16?10.10.0.0/16?g' calico.yaml
 56  vi calico.yaml 
 57  kubectl apply -f calico.yaml
 58  kubectl get nodes

worker 1 node history

 5  sudo swapoff /swap.img
 6  sudo sed -i -e '/swap.img/d' /etc/fstab
 7  curl -fsSL https://get.docker.com -o get-docker.sh
 8  sudo sh get-docker.sh
 9  sudo systemctl restart docker
 10  sudo systemctl enable docker
 11  clear
 12  git clone https://github.com/Mirantis/cri-dockerd.git
 13  wget https://storage.googleapis.com/golang/getgo/installer_linux
 14  chmod +x ./installer_linux
 15  ./installer_linux
 16  source ~/.bash_profile
 17  cd cri-dockerd
 18  mkdir bin
 19  go build -o bin/cri-dockerd
 20  mkdir -p /usr/local/bin
 21  install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
 22  cp -a packaging/systemd/* /etc/systemd/system
 23  sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
 24  systemctl daemon-reload
 25  systemctl enable cri-docker.service
 26  systemctl enable --now cri-docker.socket
 27  sudo systemctl restart docker && sudo systemctl restart cri-docker
 28  sudo systemctl status cri-docker.socket --no-pager 
 29  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

   30  sudo systemctl restart docker && sudo systemctl restart cri-docker
   31  cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

   32  cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

   33  sudo apt-get update
   34  sudo apt-get install -y apt-transport-https ca-certificates curl
   35  sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
   36  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
   37  clear
   38  sudo apt-get update
   39  sudo apt-get install -y kubelet kubeadm kubectl
   40  kubectl version --short
   41  sudo apt-mark hold kubelet kubeadm kubectl
   42  kubeadm join 211.183.3.100:6443 --token pwf42v.u1nmoe0rdzukmhy8 --discovery-token-ca-cert-hash sha256:05bb3dfff1a1629749f30411f581198581d14a2b2328e0fa805c5e7d781931c1 --cri-socket unix:///run/cri-dockerd.sock

worker 2 node history

   5  sudo swapoff /swap.img
   6  sudo sed -i -e '/swap.img/d' /etc/fstab
   7  curl -fsSL https://get.docker.com -o get-docker.sh
   8  sudo sh get-docker.sh
   9  sudo systemctl restart docker
   10  sudo systemctl enable docker
   11  clear
   12  git clone https://github.com/Mirantis/cri-dockerd.git
   13  wget https://storage.googleapis.com/golang/getgo/installer_linux
   14  chmod +x ./installer_linux
   15  ./installer_linux
   16  source ~/.bash_profile
   17  cd cri-dockerd
   18  mkdir bin
   19  go build -o bin/cri-dockerd
   20  mkdir -p /usr/local/bin
   21  install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
   22  cp -a packaging/systemd/* /etc/systemd/system
   23  sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
   24  systemctl daemon-reload
   25  systemctl enable cri-docker.service
   26  systemctl enable --now cri-docker.socket
   27  sudo systemctl restart docker && sudo systemctl restart cri-docker
   28  sudo systemctl status cri-docker.socket --no-pager 
   29  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

   30  sudo systemctl restart docker && sudo systemctl restart cri-docker
   31  cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

   32  cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

   33  sudo apt-get update
   34  sudo apt-get install -y apt-transport-https ca-certificates curl
   35  sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
   36  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
   37  clear
   38  sudo apt-get update
   39  sudo apt-get install -y kubelet kubeadm kubectl
   40  kubectl version --short
   41  sudo apt-mark hold kubelet kubeadm kubectl
   42  kubeadm join 211.183.3.100:6443 --token pwf42v.u1nmoe0rdzukmhy8 --discovery-token-ca-cert-hash sha256:05bb3dfff1a1629749f30411f581198581d14a2b2328e0fa805c5e7d781931c1 --cri-socket unix:///run/cri-dockerd.sock


컴포넌트들은 컨테이너로 이루어져 있음

root@master:~/cri-dockerd# docker ps
CONTAINER ID   IMAGE                       COMMAND                  CREATED             STATUS             PORTS     NAMES
c8ffe8615af9   5185b96f0bec                "/coredns -conf /etc…"   52 minutes ago      Up 52 minutes                k8s_coredns_coredns-787d4945fb-szkxc_kube-system_278d14ac-5230-4120-9dbd-c41420f8cae1_0
fa609ed3d08b   5185b96f0bec                "/coredns -conf /etc…"   52 minutes ago      Up 52 minutes                k8s_coredns_coredns-787d4945fb-6j6m5_kube-system_ce9b94f8-e47c-4973-8285-99489d94be8e_0
17193f835516   registry.k8s.io/pause:3.6   "/pause"                 52 minutes ago      Up 52 minutes                k8s_POD_calico-kube-controllers-7bdbfc669-vtkvx_kube-system_4db96924-e71b-4458-8178-cae780b81924_7
f9f3e6b796f7   registry.k8s.io/pause:3.6   "/pause"                 52 minutes ago      Up 52 minutes                k8s_POD_coredns-787d4945fb-szkxc_kube-system_278d14ac-5230-4120-9dbd-c41420f8cae1_5
8a6c65f2df64   registry.k8s.io/pause:3.6   "/pause"                 52 minutes ago      Up 52 minutes                k8s_POD_coredns-787d4945fb-6j6m5_kube-system_ce9b94f8-e47c-4973-8285-99489d94be8e_6
1a736b3200fd   54637cb36d4a                "start_runit"            52 minutes ago      Up 52 minutes                k8s_calico-node_calico-node-6qwqc_kube-system_c552ddb8-94ef-40cb-801e-adbe5d5e0d33_0
8509d48b28f0   registry.k8s.io/pause:3.6   "/pause"                 53 minutes ago      Up 53 minutes                k8s_POD_calico-node-6qwqc_kube-system_c552ddb8-94ef-40cb-801e-adbe5d5e0d33_0
d9ef632d4182   556768f31eb1                "/usr/local/bin/kube…"   About an hour ago   Up About an hour             k8s_kube-proxy_kube-proxy-v6s56_kube-system_ef892210-6d97-42b6-9205-d94a9c85773b_0
36a7995b5ab9   registry.k8s.io/pause:3.6   "/pause"                 About an hour ago   Up About an hour             k8s_POD_kube-proxy-v6s56_kube-system_ef892210-6d97-42b6-9205-d94a9c85773b_0
b92b9ec68745   dafd8ad70b15                "kube-scheduler --au…"   About an hour ago   Up About an hour             k8s_kube-scheduler_kube-scheduler-master_kube-system_ed005ef5c70ffeb7405e6e1e3ef0f5f2_0
3e6e6be36416   a31e1d84401e                "kube-apiserver --ad…"   About an hour ago   Up About an hour             k8s_kube-apiserver_kube-apiserver-master_kube-system_f59a75118a056a401a2dd7f00bf0971a_0
6c3db0c19859   5d7c5dfd3ba1                "kube-controller-man…"   About an hour ago   Up About an hour             k8s_kube-controller-manager_kube-controller-manager-master_kube-system_2143afa0fd4147e948b0484f607c8818_0
b91cb81d472b   fce326961ae2                "etcd --advertise-cl…"   About an hour ago   Up About an hour             k8s_etcd_etcd-master_kube-system_0a6c20b596244b014d4229cec39c7489_0
fcd2f15adc08   registry.k8s.io/pause:3.6   "/pause"                 About an hour ago   Up About an hour             k8s_POD_etcd-master_kube-system_0a6c20b596244b014d4229cec39c7489_0
28503094e79f   registry.k8s.io/pause:3.6   "/pause"                 About an hour ago   Up About an hour             k8s_POD_kube-controller-manager-master_kube-system_2143afa0fd4147e948b0484f607c8818_0
97e79a45f886   registry.k8s.io/pause:3.6   "/pause"                 About an hour ago   Up About an hour             k8s_POD_kube-apiserver-master_kube-system_f59a75118a056a401a2dd7f00bf0971a_0
389062f41732   registry.k8s.io/pause:3.6   "/pause"                 About an hour ago   Up About an hour             k8s_POD_kube-scheduler-master_kube-system_ed005ef5c70ffeb7405e6e1e3ef0f5f2_0

pod(하나 이상의 컨테이너)들은 네임스페이스를 기준으로 정리되어 있다.
지금 default 네임스페이스에 위치해있는 상태

root@master:~/cri-dockerd# kubectl get pod
No resources found in default namespace.

root@master:~/cri-dockerd# kubectl get pod --all-namespaces
NAMESPACE     NAME                                      READY   STATUS             RESTARTS   AGE
kube-system   calico-kube-controllers-7bdbfc669-vtkvx   0/1     ImagePullBackOff   0          56m
kube-system   calico-node-6qwqc                         1/1     Running            0          56m
kube-system   calico-node-ddk9t                         1/1     Running            0          56m
kube-system   calico-node-z9vsh                         1/1     Running            0          56m
kube-system   coredns-787d4945fb-6j6m5                  1/1     Running            0          70m
kube-system   coredns-787d4945fb-szkxc                  1/1     Running            0          70m
kube-system   etcd-master                               1/1     Running            0          70m
kube-system   kube-apiserver-master                     1/1     Running            0          70m
kube-system   kube-controller-manager-master            1/1     Running            0          70m
kube-system   kube-proxy-c8s7q                          1/1     Running            0          66m
kube-system   kube-proxy-fblbx                          1/1     Running            0          66m
kube-system   kube-proxy-v6s56                          1/1     Running            0          70m
kube-system   kube-scheduler-master                     1/1     Running            0          70m

controller : 내가 선언한 상태에 수렴하려고 노력한다 

root@master:~/cri-dockerd# kubectl run test --image=nginx
pod/test created
root@master:~/cri-dockerd# docker login

master, worker1, worker2 노드 docker login 



root@master:~/cri-dockerd# kubectl run test --image=nginx
pod/test created

root@master:~/cri-dockerd# curl 10.10.235.130
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

root@master:~# kubectl get pod -o wide --watch
NAME   READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
test   0/1     Pending   0          0s    <none>   <none>   <none>           <none>
test   0/1     Pending   0          0s    <none>   worker1   <none>           <none>
test   0/1     ContainerCreating   0          0s    <none>   worker1   <none>           <none>
test   0/1     ContainerCreating   0          1s    <none>   worker1   <none>           <none>
test   1/1     Running             0          5s    10.10.235.130   worker1   <none>           <none>


root@master:~/cri-dockerd# kubectl delete pod test
pod "test" deleted

root@master:~# kubectl get pod -o wide --watch
NAME   READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
test   0/1     Pending   0          0s    <none>   <none>   <none>           <none>
test   0/1     Pending   0          0s    <none>   worker1   <none>           <none>
test   0/1     ContainerCreating   0          0s    <none>   worker1   <none>           <none>
test   0/1     ContainerCreating   0          1s    <none>   worker1   <none>           <none>
test   1/1     Running             0          5s    10.10.235.130   worker1   <none>           <none>
test   1/1     Terminating         0          3m31s   10.10.235.130   worker1   <none>           <none>
test   1/1     Terminating         0          3m31s   10.10.235.130   worker1   <none>           <none>
test   0/1     Terminating         0          3m32s   10.10.235.130   worker1   <none>           <none>
test   0/1     Terminating         0          3m32s   10.10.235.130   worker1   <none>           <none>
test   0/1     Terminating         0          3m32s   10.10.235.130   worker1   <none>           <none>

yaml : 매니페스트 파일

root@master:~/cri-dockerd# vi test.yml
*******
# api 버전 명시
# 어떤 오브젝트를 쓸 것인지 결정해야 하고 오브젝트는 
# pod, namespace, replicaSet, Deployment, Persistant volume 등이 있다.

apiVersion: v1
kind: Pod # 오브젝트 명시
metadata: # 이름, 혹은 라벨
  name: test
spec:  # 원하는 상태- 계속 원하는 상태가 됐는지감시를 계속한다 만약, 충족되지 않았다면충족시키려고 노력
  containers:
    - name: test-container
      image: nginx                                                      
*******

create 말고 apply 을 주로 쓰는 이유는 yml 파일이 변경됐을 시, 자동으로 이미지의 버전을 업데이트한다


root@master:~/cri-dockerd# kubectl apply -f test.yml 
pod/test created

NAME   READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
test   0/1     Pending   0          0s    <none>   <none>   <none>           <none>
test   0/1     Pending   0          0s    <none>   worker1   <none>           <none>
test   0/1     ContainerCreating   0          0s    <none>   worker1   <none>           <none>
test   0/1     ContainerCreating   0          3s    <none>   worker1   <none>           <none>
test   1/1     Running             0          6s    10.10.235.131   worker1   <none>           <none>

root@master:~/cri-dockerd# kubectl get pod -o wide
NAME   READY   STATUS    RESTARTS   AGE   IP              NODE      NOMINATED NODE   READINESS GATES
test   1/1     Running   0          61s   10.10.235.131   worker1   <none>           <none>

제원을 더 자세히 보고싶을 때  - describe

root@master:~/cri-dockerd# kubectl delete pod test
pod "test" deleted


root@master:~/cri-dockerd# vi test.yml 
apiVersion: v1
kind: Pod # 오브젝트 명시
metadata: # 이름, 혹은 라벨
  name: test
spec:  # 원하는 상태- 계속 원하는 상태가 됐는지감시를 계속한다 만약, 충족되지 않았다면충족시키려고 노력
  containers:
    - name: test-container
      image: nginx
    - name: centos-container
      image: centos:7
      command:
        - sleep
        - "10000"

replicaset

root@master:~/cri-dockerd# kubectl delete pod test
pod "test" deleted
root@master:~/cri-dockerd# vi rs.yml

**********
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: rs
spec:
  selector:
    matchLabels:
      app: test
  replicas: 3
  template:
    metadata:
      name: test
      labels:
        app: test
    spec:
      containers:
        - name: test-container
          image: nginx

**********

root@master:~/cri-dockerd# kubectl get pod
NAME       READY   STATUS             RESTARTS   AGE
rs-5zzlg   1/1     Running            0          3m19s
rs-hhwgk   0/1     ImagePullBackOff   0          3m19s
rs-sgf6f   1/1     Running            0          3m19s

두번째 pod 는 자체오류로 running 이라고 가정해서 진행

일단 삭제 해보자

root@master:~/cri-dockerd# kubectl delete pod rs-hhwgk

같은 오류 돈 안내서 그런거 같다

root@master:~/cri-dockerd# kubectl delete rs rs

root@master:~/cri-dockerd# kubectl get pod
No resources found in default namespace.

Deployment

root@master:~/cri-dockerd# vi deploy-nginx.yml

****

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-nginx
  template:
    metadata:
      name: my-nginx-pod
      labels:
        app: my-nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
****

root@master:~/cri-dockerd# kubectl apply -f deploy-nginx.yml 
root@master:~/cri-dockerd# kubectl delete deployment my-nginx-deployment


root@master:~/cri-dockerd# kubectl get pod
NAME                                   READY   STATUS             RESTARTS   AGE
my-nginx-deployment-7c58d86666-4nghn   1/1     Running            0          7m37s
my-nginx-deployment-7c58d86666-58k9p   0/1     ImagePullBackOff   0          7m37s
my-nginx-deployment-7c58d86666-tc4sc   1/1     Running            0          7m37s
root@master:~/cri-dockerd# kubectl get replicasets
NAME                             DESIRED   CURRENT   READY   AGE
my-nginx-deployment-7c58d86666   3         3         2       8m38s
profile
무럭무럭 자라볼까

0개의 댓글