手把手离线部署kubernetesV1.11.0 集群

手把手离线部署kubernetesV1.11.0 集群,便于了解每个服务是需要什么参数运行的。

 

一、服务器环境

linux:centos7
kubernetes:V1.11.0
etcd:V3.3.8
docker:V1.13.1
各节点所需部署的服务
master:172.16.36.137,部署etcd、kube-apiserver、kube-controller-manager、kube-scheduler
node1:172.16.36.138,部署docker 、kubelet、kube-proxy
各节点需要注意的
1、关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
2、禁用selinux
setenforce 0
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
3、关闭swap

sudo swapoff -a

#要永久禁掉swap分区,打开如下文件注释掉swap那一行 

# sudo vi /etc/fstab

 

二、安装部署etc,具体步骤参照之前写的文章《etc集群部署》


三、master节点
1、下载kubernetes-server-linux-amd64.tar.gz,官方下载地址:https://kubernetes.io/docs/imported/release/notes/,可能需要翻墙下载
2、解压,tar –zxvf kubernetes-server-linux-amd64.tar.gz
3、将里面的二进制命令,kube-apiserver、kube-controller-manager、kube-scheduler、kubectl、kubeadm复制到/usr/bin下
4、创建配置目录,mkdir –p /etc/kubernetes
5、新建config通用配置文件,vim /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://172.16.36.137:8080"


6、新建apiserver配置文件,vim /etc/kubernetes/apiserver
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#


# The address on the local server to listen to.
KUBE_API_ADDRESS="--address=0.0.0.0"
#KUBE_API_ADDRESS="--insecure-bind-address=127.0.0.1"


# The port on the local server to listen on.
KUBE_API_PORT="--port=8080"


# Port minions listen on
KUBELET_PORT="--kubelet-port=10250"


# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://172.16.36.137:2379 "


# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=172.16.0.0/24"


# default admission control policies
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"


# Add your own!
KUBE_API_ARGS="--service-node-port-range=1-65535 --insecure-bind-address=0.0.0.0"


7、新增apiserver服务,vim /usr/lib/systemd/system/kube-apiserver.service
[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


8、新建controller-manager配置文件,vim /etc/kubernetes/controller-manager
KUBE_CONTROLLER_MANAGER_ARGS=""


9、新增controller-manage服务,vim /usr/lib/systemd/system/kube-controller-manager.service
[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


10、新建scheduler配置文件,vim /etc/kubernetes/scheduler
KUBE_SCHEDULER_ARGS=""


11、新增scheduler服务,vim /usr/lib/systemd/system/kube-scheduler.service
[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


12、master节点启动所需服务
systemctl daemon-reload
systemctl enable etcd
systemctl enable kube-apiserver
systemctl enable kube-controller-manager
systemctl enable kube-scheduler
systemctl start etcd
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler


13、查看启动情况 systemctl status 服务名 -l
Active: active (running)为正常启动,不正常查看错误提示处理


四、node节点
1、下载kubernetes-node-linux-amd64.tar.gz,官方下载地址:https://kubernetes.io/docs/imported/release/notes/,可能需要翻墙下载
2、解压,tar –zxvf kubernetes-node-linux-amd64.tar.gz
3、将里面的二进制命令,kubelet、kube-proxy、kubectl、kubeadm复制到/usr/bin下
4、创建配置目录,mkdir –p /etc/kubernetes
5、新建config通用配置文件,vim /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://172.16.36.137:8080"


6、新建kubelet配置文件,vim /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=172.16.36.138"
KUBELET_HOSTNAME="--hostname-override=172.16.36.138"
#KUBELET_API_SERVER="--api-servers=http://172.16.36.137:8080"


# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS="--kubeconfig=/etc/kubernetes/kubeconfig --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice --cluster-dns=172.16.0.0 --cgroup-driver=systemd --enable-server=true --enable-debugging-handlers=true"


注意:这里需要说明的是kubernetesV1.9 开始已经不支持--api-servers参数,需要指定--kubeconfig=/etc/kubernetes/kubeconfig配置文件来指明master的地址,否则master主机执行kubectl get nodes,会提示找不到节点


7、新建kubelet的另一个配置文件,vim /etc/kubernetes/kubeconfig
apiVersion: v1
kind: Config
users:
- name: kubelet
clusters:
- name: kubernetes
  cluster:
    server: http://172.16.36.137:8080
contexts:
- context:
    cluster: kubernetes
    user: kubelet
  name: service-account-context
current-context: service-account-context


8、新建kubelet服务,vim /usr/lib/systemd/system/kubelet.service
[Unit]
    Description=Kubernetes Kubelet
    Documentation=https://github.com/GoogleCloudPlatform/kubernetes
    After=docker.service
    Requires=docker.service


    [Service]
    WorkingDirectory=/var/lib/kubelet
    EnvironmentFile=-/etc/kubernetes/config
    EnvironmentFile=-/etc/kubernetes/kubelet
    ExecStart=/usr/bin/kubelet \
            $KUBE_LOGTOSTDERR \
            $KUBE_LOG_LEVEL \
            $KUBELET_ADDRESS \
            $KUBELET_HOSTNAME \
            $KUBE_ALLOW_PRIV \
            $KUBELET_POD_INFRA_CONTAINER \
            $KUBELET_ARGS
    Restart=on-failure
    KillMode=process


    [Install]
WantedBy=multi-user.target


9、新建kube-proxy配置文件,vim /etc/kubernetes/proxy
# kubernetes proxy config
# default config should be adequate
# Add your own!
 KUBE_PROXY_ARGS="--bind-address=172.16.36.138 --hostname-override=172.16.36.138"


10、新建kube-proxy服务,vim /usr/lib/systemd/system/kube-proxy.service
[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


11、安装docker,yum install docker –y


12、node节点启动所需服务
systemctl daemon-reload
systemctl enable docker
systemctl enable kubelet
systemctl enable kube-proxy
systemctl start docker
systemctl start kubelet
systemctl start kube-proxy r


13、查看启动情况 systemctl status 服务名 -l
Active: active (running)为正常启动,不正常查看错误提示处理


五、验证是否k8s集群部署成功
在master节点,执行kubectl get nodes


 

在master节点,执行kubectl get cs 

 

                                     如想了解更多架构监控,请扫二维码关注我个人公众号以及转发分享

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试