#! /bin/bash
mkdir /data && cd /data
wget https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz # master
wget https://dl.k8s.io/v1.9.9/kubernetes-server-linux-amd64.tar.gz #master
tar -zxvf etcd-v3.3.9-linux-amd64.tar.gz && etcd-v3.3.9-linux-amd64
mv etcd* /usr/bin
mkdir /etc/etcd
cat <
ETCD_NAME=ansible-k8s2
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_DATA_DIR="/var/lib/etcd/"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.29.102:2379"
EOF
tar -zxvf kubernetes-server-linux-amd64.tar.gz && cd kubernetes/server/bin/
mv kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet kubectl /usr/bin
mkdir /etc/kubernetes && cd /etc/kubernetes
cat <
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.29.102:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=192.168.4.0/24"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
KUBE_API_ARGS=""
EOF
cat <
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://192.168.29.102:8080"
EOF
cat <
KUBE_CONTROLLER_MANAGER_ARGS=""
EOF
cat <
KUBE_SCHEDULER_ARGS=""
EOF
cat <
[ Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target
[ Service]
User=root
Type=notify
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/bin/etcd
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000
[ Install]
WantedBy=multi-user.target
EOF
cat <
[ Unit]
Description=Kubernetes API Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
After=etcd.service
Wants=etcd.service
[ Service]
User=root
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/apiserver
ExecStart=/usr/bin/kube-apiserver \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_ETCD_SERVERS \
$KUBE_API_ADDRESS \
$KUBE_API_PORT \
$KUBELET_PORT \
$KUBE_ALLOW_PRIV \
$KUBE_SERVICE_ADDRESSES \
$KUBE_ADMISSION_CONTROL \
$KUBE_API_ARGS
Restart=on-failure
Type=notify
LimitNOFILE=65536
[ Install]
WantedBy=multi-user.target
EOF
cat <
[ Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=etcd.service
After=kube-apiserver.service
Requires=etcd.service
Requires=kube-apiserver.service
[ Service]
User=root
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/controller-manager
ExecStart=/usr/bin/kube-controller-manager \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_MASTER \
$KUBE_CONTROLLER_MANAGER_ARGS
Restart=on-failure
LimitNOFILE=65536
[ Install]
WantedBy=multi-user.target
EOF
cat <
[ Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes
[ Service]
User=root
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/scheduler
ExecStart=/usr/bin/kube-scheduler \
$KUBE_LOGTOSTDERR \
$KUBE_MASTER
Restart=on-failure
LimitNOFILE=65536
[ Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
for service in etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service;
do systemctl enable $service;
done
for service in etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service;
do systemctl start $service;
done
for service in etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service;
do systemctl status $service;
done
wget wget https://dl.k8s.io/v1.9.9/kubernetes-node-linux-amd64.tar.gz
tar -zxvf kubernetes-node-linux-amd64.tar.gz && cd cd kubernetes/node/bin/
mv kube* /usr/bin
mkdir -p /etc/kubernetes && cd /etc/kubernetes
cat <
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=3"
KUBE_ALLOW_PRIV="--allow-privileged=false"
EOF
mkdir /var/lib/kubelet
cat <
apiVersion: v1
kind: Config
users:
clusters:
cluster:
server: http://192.168.29.102:8080
contexts:
cluster: kubernetes
user: kubelet
name: service-account-context
current-context: service-account-context
EOF
cat <
KUBELET_HOSTNAME="--hostname-override=192.168.29.103"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS="--enable-server=true --enable-debugging-handlers=true --fail-swap-on=false --kubeconfig=/var/lib/kubelet/kubeconfig"
EOF
cat <
KUBE_PROXY_ARGS=""
EOF
cat <
[ Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service #
Required = docker.service#最初にdockerをインストールしてから、workerを起動します
[ Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBELET_API_SERVER \
$KUBELET_ADDRESS \
$KUBELET_PORT \
$KUBELET_HOSTNAME \
$KUBE_ALLOW_PRIV \
$KUBELET_POD_INFRA_CONTAINER \
$KUBELET_ARGS
Restart=on-failure
KillMode=process
[ Install]
WantedBy=multi-user.target
EOF
cat <
[ Unit]
Description=Kubernetes Proxy
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
[ Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/proxy
ExecStart=/usr/bin/kube-proxy \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_MASTER \
$KUBE_PROXY_ARGS
Restart=on-failure
LimitNOFILE=65536
[ Install]
WantedBy=multi-user.target
EOF
cd /data/
yum -y install container-selinux libcgroup libltdl.so.7 pigz libtool-ltdl
rpm -ivh docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm --nodeps#依存関係の問題が発生する可能性があります
systemctl daemon-reload
for service in docker.service kube-proxy.service kubelet.service;
do systemctl enable $service;
done
for service in docker.service kube-proxy.service kubelet.service;
do systemctl start $service;
done
[ root@ansible-k8s2 system]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
192.168.29.103 Ready
[ root@ansible-k8s2 system]# kubectl get cs
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}
scheduler Healthy ok
githubアドレス:https://github.com/chances-for-those-who-have-prepared/study/blob/master/k8s/install_k8s_by_manual
ご不明な点がございましたら、githubアドレスを参照してください:https://github.com/chances-for-those-who-have-prepared/study/issues
Recommended Posts