株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

 

Kubernetes

参考

https://www.server-world.info/query?os=Ubuntu_20.04&p=kubernetes&f=2

https://kubernetes.io/ja/docs/setup/production-environment/tools/kubeadm/_print/

前提

  • MasterノードはCPUが2つ以上必要
  • swapはOFFにする
  • Credentialは/etc/kubernetes/admin.confがあるので、クライアントから実行するときはこれをコピる

全ノード

dockerインストール

apt -y install docker.io apt-transport-https vim

systemdを使うようにする

cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

docker起動

systemctl restart docker
systemctl enable docker

iptables-lagacyにする

root@master:~# update-alternatives --config iptables
There are 2 choices for the alternative iptables (providing /usr/sbin/iptables).

  Selection    Path                       Priority   Status
------------------------------------------------------------
  0            /usr/sbin/iptables-nft      20        auto mode
* 1            /usr/sbin/iptables-legacy   10        manual mode
  2            /usr/sbin/iptables-nft      20        manual mode

SwapをOFFにする

swapoff -a

root@master:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-gIgYoX5IsD2ZOigjA3swD2HATXd1QiDsIomOmkPDjSm5tC6f27ERL27m5rCtNPc9 / ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/a5ee61f4-178d-470f-9b23-cc7461595e0b /boot ext4 defaults 0 1
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/D8DE-26AC /boot/efi vfat defaults 0 1
#/swap.img      none    swap    sw      0       0

ツールインストール

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
apt update
apt -y install kubeadm kubelet kubectl

Master

  • –apiserver-advertise-address=192.168.11.171はNICが2つ以上あるときは必須
    • NICが1つなら指定しなくてもOK
kubeadm init --apiserver-advertise-address=192.168.11.171 --pod-network-cidr=10.244.0.0/16

初期化

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:

kubeadm join 192.168.11.171:6443 --token yg4y0v.uipod29qg9b7czia \
        --discovery-token-ca-cert-hash sha256:8f17f3377c4f983d3a61a1b9f094831ea1eb1a7028cd95c1209cc299a94f88be

Node側で実行するので控えておく

kubeadm join 192.168.11.171:6443 --token yg4y0v.uipod29qg9b7czia \
        --discovery-token-ca-cert-hash sha256:8f17f3377c4f983d3a61a1b9f094831ea1eb1a7028cd95c1209cc299a94f88be

資格情報をセット

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

Falnnelをインストールしてネットワークを構築する

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get nodes
kubectl get pods -A

Node

クラスタに参加

kubeadm join 192.168.11.171:6443 --token yg4y0v.uipod29qg9b7czia \
        --discovery-token-ca-cert-hash sha256:8f17f3377c4f983d3a61a1b9f094831ea1eb1a7028cd95c1209cc299a94f88be

Client

scp -p administrator@192.168.11.171:~/config .kube/config

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)