12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7でのKubernetes クラスタ構築(master編)

Last updated at Posted at 2018-09-27

こちらを参考に、CentOS7上にkubernetesクラスタを構築した手順をまとめました。

実行環境は次の通りです。

  • CentOS 7.4
  • kubernetes v1.5.2
  • flanneld 0.7.1
  • etcd 3.2.22
  • Docker 1.13.1

##kubernetesのインストール
etcd, kubernetes, flannelをインストール

  • etcd: クラスタ間の管理情報共有機能
  • flannel: コンテナ間の内部VXLANネットワーク
# vi /etc/hosts
10.44.59.239  master

yum -y install etcd kubernetes flannel

etcdの設定(外部からの接続を許可)と起動

# vi /etc/etcd/etcd.conf
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"

# systemctl start etcd
# systemctl enable etcd

flannelの設定 (内部仮想ネットワークのアドレスを指定) と起動

# etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/24"}'

# systemctl start flanneld
# systemctl enable flanneld

##kubernetesの設定
RSA鍵の発行

# openssl genrsa -out /etc/kubernetes/serviceaccount.key 2048

##マスターサーバの指定

# vi /etc/kubernetes/config
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://10.44.59.239:8080"

##自マシンのホスト名とAPI Serverの設定

# vi /etc/kubernetes/kubelet
KUBELET_HOSTNAME="--hostname-override=master"
KUBELET_API_SERVER="--api-servers=http://10.44.59.239:8080"

KUBELET_ADDRESS="--address=10.44.59.239" に変更 (2019/1/22 追記 

##API Serverの設定

  • KUBE_API_ADDRESSにマスターサーバーのIPアドレスを指定
  • KUBE_API_ARGSに作成したRSA鍵のパスを指定
# vi /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=10.44.59.239"
KUBE_ETCD_SERVERS="--etcd-servers=http://10.44.59.239:2379"
KUBE_API_ARGS="--service_account_key_file=/etc/kubernetes/serviceaccount.key"

##controller-manager
鍵ファイルの設定

# vi /etc/kubernetes/controller-manager
# Add your own!
KUBE_CONTROLLER_MANAGER_ARGS="--service_account_private_key_file=/etc/kubernetes/serviceaccount.key"

サービスの起動

# systemctl start kube-apiserver
# systemctl start kube-controller-manager
# systemctl start kube-scheduler
# systemctl start kube-proxy
# systemctl start kubelet

# systemctl enable flanneld
# systemctl enable etcd
# systemctl enable kube-apiserver
# systemctl enable kube-controller-manager
# systemctl enable kube-scheduler
# systemctl enable kube-proxy
# systemctl enable kubelet

kubectlコマンドによる設定

# kubectl config set-cluster cluster --server=http://master:8080
# kubectl config set-credentials cluster-admin --username=admin --password=XXXXX
# kubectl config set-context cluster --cluster=cluster --user=cluster-admin
# kubectl config use-context cluster

設定確認

# kubectl config view
apiVersion: v1
clusters:
- cluster:
    server: http://master:8080
  name: cluster
contexts:
- context:
    cluster: cluster
    user: cluster-admin
  name: cluster

##クラスタ情報の確認

# kubectl cluster-info
Kubernetes master is running at http://master:8080

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

node情報の確認

# kubectl get nodes
NAME      STATUS    AGE
master    Ready     10m

##firewallの設定
workerとの通信用に、2379、8080ポートを開ける

# firewall-cmd --add-port=2379/tcp --zone=public --permanent
# firewall-cmd --add-port=8080/tcp --zone=public --permanent
# firewall-cmd --reload

参考
Kubernetes クラスタ構築(worker編)

12
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?