kubesprayでCentOS7上にKubernetes環境を構築してみた

##要旨
CentOS7上にシングルノードのKubernetes環境を構築します。
構築ツールにはkubesprayを使用。

例のごとくお試しです。
細かい設定は追って調査します。

##ホスト設定
firewallをオフ
（今回は省略）

Swapをオフ

```
swapoff -a
```

SELinux

```
setenforce 0
```

##パッケージインストール

```
yum install -y epel-release
yum install -y ansible git gcc python-pip python-devel python-netaddr libffi-devel openssl-devel
pip install pip --upgrade
pip install jinja2
```

python3

```
yum install python34
```

##kubesprayをクローン

```
git clone https://github.com/kubernetes-incubator/kubespray.git
cd kubespray
```

```
pip install -r requirements.txt
```

##Inventory設定

```
cp -rfp inventory/sample inventory/mycluster
declare -a IPS=(192.168.33.10)
vi inventory/mycluster/inventory.ini
```

```
[all]
node1 ansible_host=192.168.33.10   ip=192.168.33.10 etcd_member_name=etcd1

# ## configure a bastion host if your nodes are not directly reachable
ansible_host=192.168.33.10 ansible_user=vagrant

[kube-master]
node1

[etcd]
node1

[kube-node]
node1

[k8s-cluster:children]
kube-master
kube-node

```

##SSH設定

```
ssh-keygen -t rsa
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
```

##インストール実行

```
ansible-playbook -i inventory/mycluster/inventory.ini cluster.yml -v
```

10分ほどで完了しました。

```
PLAY RECAP ******************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0
node1                      : ok=400  changed=122  unreachable=0    failed=0
```

##kubectlインストール
なぜかkubectlはインストールされないので、インストールします。

```
sudo sh -c "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
"
yum install -y kubectl
```

##デモ

```
kubectl create namespace sock-shop
kubectl create -f "https://github.com/microservices-demo/microservices-demo/blob/master/deploy/kubernetes/complete-demo.yaml?raw=true"
```

```
kubectl get pods --all-namespaces
NAMESPACE     NAME                                      READY   STATUS    RESTARTS   AGE
kube-system   calico-kube-controllers-874794d57-7lmnx   1/1     Running   0          15m
kube-system   calico-node-8c7j6                         1/1     Running   0          15m
kube-system   coredns-644c686c9-gb72g                   1/1     Running   0          15m
kube-system   coredns-644c686c9-sf9bl                   0/1     Pending   0          15m
kube-system   dns-autoscaler-586f58b8bf-784jk           1/1     Running   0          15m
kube-system   kube-apiserver-node1                      1/1     Running   0          16m
kube-system   kube-controller-manager-node1             1/1     Running   0          16m
kube-system   kube-proxy-942n5                          1/1     Running   0          15m
kube-system   kube-scheduler-node1                      1/1     Running   0          16m
kube-system   kubernetes-dashboard-8457c55f89-69jqx     1/1     Running   0          15m
sock-shop     carts-648d5f498d-s2dbc                    1/1     Running   0          4m27s
sock-shop     carts-db-64b6cc584f-qrs22                 1/1     Running   0          4m27s
sock-shop     catalogue-6759fc9bf5-2j8lw                1/1     Running   0          4m27s
sock-shop     catalogue-db-99cbcbb88-dn9wb              1/1     Running   0          4m27s
sock-shop     front-end-77b48955b6-jh2cn                1/1     Running   0          4m26s
sock-shop     orders-6496fcd6f7-qnp7d                   1/1     Running   0          4m26s
sock-shop     orders-db-86f5c494b9-qskpb                1/1     Running   0          4m26s
sock-shop     payment-7779bc549c-dhxjj                  1/1     Running   0          4m26s
sock-shop     queue-master-6bb75d8867-js2sq             1/1     Running   0          4m26s
sock-shop     rabbitmq-549bb9596f-qgnjm                 1/1     Running   0          4m26s
sock-shop     shipping-65769d99d7-qgrbq                 1/1     Running   0          4m26s
sock-shop     user-6b445f9b5b-2rkcv                     1/1     Running   0          4m25s
sock-shop     user-db-56bbb4c6db-gdzrl                  1/1     Running   0          4m25s
```

![image.png](https://qiita-image-store.s3.amazonaws.com/0/388624/d0130a55-5d69-a45f-5145-4113a0bf2457.png)

##課題
coreDNSのpodが一つ動いてない
etcdの設定に自信がない