[k8s][CentOS7]kubernetesを触ってみる

CentOS7に k8s環境を作ってみる

kubernettus Master Node

メモ

yum install bash-completion wget -y
wget https://github.com/terralinux/systemd/raw/master/src/systemctl-bash-completion.sh -O /etc/bash_completion.d/systemctl-bash-completion.sh

必要なものをインストール

[root@k8s-master ~]# yum install vim curl net-tools -y

install

[root@k8s-master ~]# cat <<EOF > /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.gpg
EOF

[root@k8s-master ~]# yum install docker kubelet kubeadm kubectl
================================================================================
 Package              アーキテクチャー
                             バージョン                        リポジトリー
                                                                           容量
================================================================================
インストール中:
 docker               x86_64 2:1.13.1-63.git94f4240.el7.centos extras      16 M
 kubeadm              x86_64 1.10.3-0                          kubernetes  17 M
 kubectl              x86_64 1.10.3-0                          kubernetes 7.6 M
 kubelet              x86_64 1.10.3-0                          kubernetes  17 M
依存性関連でのインストールをします:
 audit-libs-python    x86_64 2.8.1-3.el7                       base        75 k
 checkpolicy          x86_64 2.5-6.el7                         base       294 k
 container-selinux    noarch 2:2.55-1.el7                      extras      34 k
 container-storage-setup
                      noarch 0.9.0-1.rhel75.gite0997c3.el7     extras      33 k
 docker-client        x86_64 2:1.13.1-63.git94f4240.el7.centos extras     3.8 M
 docker-common        x86_64 2:1.13.1-63.git94f4240.el7.centos extras      88 k
 kubernetes-cni       x86_64 0.6.0-0                           kubernetes 8.6 M
 libcgroup            x86_64 0.41-15.el7                       base        65 k
 libsemanage-python   x86_64 2.5-11.el7                        base       112 k
 oci-register-machine x86_64 1:0-6.git2b44233.el7              extras     1.1 M
 oci-systemd-hook     x86_64 1:0.1.15-2.gitc04483d.el7         extras      33 k
 oci-umount           x86_64 2:2.3.3-3.gite3c9055.el7          extras      32 k
 policycoreutils-python
                      x86_64 2.5-22.el7                        base       454 k
 setools-libs         x86_64 3.3.8-2.el7                       base       619 k
 skopeo-containers    x86_64 1:0.1.29-3.dev.git7add6fc.el7.0   extras      15 k
 socat                x86_64 1.7.3.2-2.el7                     base       290 k
 yajl                 x86_64 2.0.4-4.el7                       base        39 k
依存性関連での更新をします:
 audit                x86_64 2.8.1-3.el7                       base       247 k
 audit-libs           x86_64 2.8.1-3.el7                       base        99 k
 libselinux           x86_64 2.5-12.el7                        base       162 k
 libselinux-python    x86_64 2.5-12.el7                        base       235 k
 libselinux-utils     x86_64 2.5-12.el7                        base       151 k
 libsemanage          x86_64 2.5-11.el7                        base       150 k
 libsepol             x86_64 2.5-8.1.el7                       base       297 k
 policycoreutils      x86_64 2.5-22.el7                        base       867 k
 selinux-policy       noarch 3.13.1-192.el7_5.3                updates    453 k
 selinux-policy-targeted
                      noarch 3.13.1-192.el7_5.3                updates    6.6 M



start & enabled

[root@k8s-master ~]# systemctl enable docker && systemctl start docker
[root@k8s-master ~]# systemctl enable kubelet && systemctl start kubelet

Kubernetes Masterの作成

[user@k8s-master ~]# sudo swapoff -a # offにしないとエラーになる
[root@k8s-master ~]# vim /etc/fstab # ついでに無効化
[user@k8s-master ~]# sudo kubeadm init
Your Kubernetes master 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

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/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 153.127.203.79:6443 --token lfo9fk.jjweocwv4lgx3hm3 --discovery-token-ca-cert-hash sha256:af2b188820dd4a9095d70d397f7566486bbf5e8a6009758a264522de985e31ac

とあるので、もろもろ対応

[root@k8s-master ~]# mkdir -p $HOME/.kube
[root@k8s-master ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@k8s-master ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@k8s-master ~]#

ネットワークの作成

ちなみに、Cluster Networkの選択肢はたくさんある。 https://kubernetes.io/docs/concepts/cluster-administration/networking/#how-to-achieve-this

[root@k8s-master ~]# export kubever=$(kubectl version | base64 | tr -d '\n')
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-ver
sion=$kubever"
serviceaccount "weave-net" created
clusterrole.rbac.authorization.k8s.io "weave-net" created
clusterrolebinding.rbac.authorization.k8s.io "weave-net" created
role.rbac.authorization.k8s.io "weave-net" created
rolebinding.rbac.authorization.k8s.io "weave-net" created
daemonset.extensions "weave-net" created

確認

[root@k8s-master ~]# kubectl get nodes
NAME         STATUS    ROLES     AGE       VERSION
k8s-master   Ready     master    12m       v1.10.3

kubenetus WorkerNode

必要なものをインストール

[root@k8s-worker1 ~]# yum install vim curl net-tools -y

install

[root@k8s-worker1 ~]# cat <<EOF > /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.gpg
EOF

[root@k8s-worker1 ~]# yum install docker kubelet kubeadm kubectl
================================================================================
 Package              アーキテクチャー
                             バージョン                        リポジトリー
                                                                           容量
================================================================================
インストール中:
 docker               x86_64 2:1.13.1-63.git94f4240.el7.centos extras      16 M
 kubeadm              x86_64 1.10.3-0                          kubernetes  17 M
 kubectl              x86_64 1.10.3-0                          kubernetes 7.6 M
 kubelet              x86_64 1.10.3-0                          kubernetes  17 M
依存性関連でのインストールをします:
 audit-libs-python    x86_64 2.8.1-3.el7                       base        75 k
 checkpolicy          x86_64 2.5-6.el7                         base       294 k
 container-selinux    noarch 2:2.55-1.el7                      extras      34 k
 container-storage-setup
                      noarch 0.9.0-1.rhel75.gite0997c3.el7     extras      33 k
 docker-client        x86_64 2:1.13.1-63.git94f4240.el7.centos extras     3.8 M
 docker-common        x86_64 2:1.13.1-63.git94f4240.el7.centos extras      88 k
 kubernetes-cni       x86_64 0.6.0-0                           kubernetes 8.6 M
 libcgroup            x86_64 0.41-15.el7                       base        65 k
 libsemanage-python   x86_64 2.5-11.el7                        base       112 k
 oci-register-machine x86_64 1:0-6.git2b44233.el7              extras     1.1 M
 oci-systemd-hook     x86_64 1:0.1.15-2.gitc04483d.el7         extras      33 k
 oci-umount           x86_64 2:2.3.3-3.gite3c9055.el7          extras      32 k
 policycoreutils-python
                      x86_64 2.5-22.el7                        base       454 k
 setools-libs         x86_64 3.3.8-2.el7                       base       619 k
 skopeo-containers    x86_64 1:0.1.29-3.dev.git7add6fc.el7.0   extras      15 k
 socat                x86_64 1.7.3.2-2.el7                     base       290 k
 yajl                 x86_64 2.0.4-4.el7                       base        39 k
依存性関連での更新をします:
 audit                x86_64 2.8.1-3.el7                       base       247 k
 audit-libs           x86_64 2.8.1-3.el7                       base        99 k
 libselinux           x86_64 2.5-12.el7                        base       162 k
 libselinux-python    x86_64 2.5-12.el7                        base       235 k
 libselinux-utils     x86_64 2.5-12.el7                        base       151 k
 libsemanage          x86_64 2.5-11.el7                        base       150 k
 libsepol             x86_64 2.5-8.1.el7                       base       297 k
 policycoreutils      x86_64 2.5-22.el7                        base       867 k
 selinux-policy       noarch 3.13.1-192.el7_5.3                updates    453 k
 selinux-policy-targeted
                      noarch 3.13.1-192.el7_5.3                updates    6.6 M



start & enabled

[root@k8s-worker1 ~]# systemctl enable docker && systemctl start docker
[root@k8s-worker1 ~]# systemctl enable kubelet && systemctl start kubelet

worker nodeをmaster nodeにjoinさせる

[root@k8s-worker1 ~]# sudo swapoff -a
[root@k8s-worker1 ~]# vim /etc/fstab # ついでに無効化

masterを作成したときのメッセージを確認するんだ、、、!!!!

[root@k8s-worker1 ~]# kubeadm join 153.127.203.79:6443 --token lfo9fk.jjweocwv4lgx3hm3 --discovery-token-ca-cert-hash sha256:af2b188820dd4a9095d70d397f7566486bbf5e8a6009758a264522de985e31ac

masterで確認

[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 25m v1.10.3
k8s-worker1 Ready <none> 28s v1.10.3

sannkou

https://qiita.com/sheepland/items/d63bfe24c8e363132f7a
https://qiita.com/sugimount/items/9a2f64746e54f4835f5a

Updated: 2018年12月8日 — 11:59 AM

Leave a Reply

Your email address will not be published. Required fields are marked *

備忘録の覚書 © 2017 Frontier Theme