zoukankan      html  css  js  c++  java
  • Kubernetes集群初探

    上文我们在一台虚机上演示了Kubernetes基于redis和docker的guestbook留言簿案例,本文我们将通过配置Kubernetes集群的方式继续深入研究。集群组件安装如下配置。
    IP NAME Component
    192.168.56.103 centos-master etcd,kube-apiserver,kube-controller-manager,kube-scheduler
    192.168.56.105 centos-node01 kube-proxy,kubelet,docker
    192.168.56.107 centos-node02 kube-proxy,kubelet,docker
    主机环境:centos 7,三台虚机。

    1.准备工作
    以下工作在每台虚机执行。
    1.1 停止防火墙
    #systemctl disable firewalld
    #systemctl stop firewalld
    1.2 修改iptables
    yum install iptables-services
    vi /etc/sysconfig/iptables把icmp-host-prohibited两条注释掉
    # sample configuration for iptables service
    # you can edit this manually or use system-config-firewall
    # please do not ask us to add additional ports/services to this default configuration
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    #-A INPUT -j REJECT --reject-with icmp-host-prohibited
    #-A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
    重启iptables
    #systemctl restart iptables
    1.3 使用阿里镜像(或other)
    #wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    1.4 更新主机列表
    #echo "192.168.56.103 CentOS7.2  
    192.168.56.105 CentOS7-1 
    192.168.56.107 CentOS7-2"  >> /etc/hosts
    2.安装配置kubernetes master
    2.1 在centos-master上安装
    #yum install kubernetes-master
    #yum install etcd
    2.2配置 Kubernetes services
    #vi /etc/kubernetes/config
    #### kubernetes system config## The following values are used to configure various aspects of all# kubernetes services, including##   kube-apiserver.service#   kube-controller-manager.service#   kube-scheduler.service#   kubelet.service#   kube-proxy.service# logging to stderr means we get it in the systemd journalKUBE_LOGTOSTDERR="--logtostderr=true"# journal message level, 0 is debugKUBE_LOG_LEVEL="--v=0"# Should this cluster be allowed to run privileged docker containersKUBE_ALLOW_PRIV="--allow-privileged=false"# How the controller-manager, scheduler, and proxy find the apiserverKUBE_MASTER="--master=http://centos-master:8080"
    2.3配置Kubernetes API server
    #vi /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="--insecure-bind-address=0.0.0.0"# The port on the local server to listen on.KUBE_API_PORT="--insecure-port=8080"# Port minions listen on#KUBELET_PORT="--kubelet-port=10250"# Comma separated list of nodes in the etcd clusterKUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"# Address range to use for servicesKUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"# default admission control policiesKUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"# Add your own!KUBE_API_ARGS=""
    2.4 启动服务
    for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do     systemctl restart $SERVICES    systemctl enable $SERVICES    systemctl status $SERVICES done

    2.5 停止服务

    for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do 
        systemctl stop $SERVICES
    done
    
    3.安装配置kubernetes node
    3.1 在centos-node01及centos-node02上安装
    #yum install kubernetes-node
    #vi /etc/kubernetes/config
    #### kubernetes system config## The following values are used to configure various aspects of all# kubernetes services, including##   kube-apiserver.service#   kube-controller-manager.service#   kube-scheduler.service#   kubelet.service#   kube-proxy.service# logging to stderr means we get it in the systemd journalKUBE_LOGTOSTDERR="--logtostderr=true"# journal message level, 0 is debugKUBE_LOG_LEVEL="--v=0"# Should this cluster be allowed to run privileged docker containersKUBE_ALLOW_PRIV="--allow-privileged=false"# How the controller-manager, scheduler, and proxy find the apiserverKUBE_MASTER="--master=http://centos-master:8080"
    3.2 配置 kubelet文件
    vi /etc/kubernetes/kubelet
    centos-node01
    #### kubernetes kubelet (minion) config# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)KUBELET_ADDRESS="--address=0.0.0.0"# The port for the info server to serve onKUBELET_PORT="--port=10250"# You may leave this blank to use the actual hostnameKUBELET_HOSTNAME="--hostname-override=centos-minion01"# location of the api-serverKUBELET_API_SERVER="--api-servers=http://centos-master:8080"# pod infrastructure containerKUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"# Add your own!KUBELET_ARGS=""
    centos-node02
    ###
    # kubernetes kubelet (minion) config# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)KUBELET_ADDRESS="--address=0.0.0.0"# The port for the info server to serve onKUBELET_PORT="--port=10250"# You may leave this blank to use the actual hostnameKUBELET_HOSTNAME="--hostname-override=centos-minion02"# location of the api-serverKUBELET_API_SERVER="--api-servers=http://centos-master:8080"# pod infrastructure containerKUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"# Add your own!KUBELET_ARGS=""
    3.3 配置config文件
         vi /etc/kubernetes/config
    #### kubernetes system config## The following values are used to configure various aspects of all# kubernetes services, including##   kube-apiserver.service#   kube-controller-manager.service#   kube-scheduler.service#   kubelet.service#   kube-proxy.service# logging to stderr means we get it in the systemd journalKUBE_LOGTOSTDERR="--logtostderr=true"# journal message level, 0 is debugKUBE_LOG_LEVEL="--v=0"# Should this cluster be allowed to run privileged docker containersKUBE_ALLOW_PRIV="--allow-privileged=false"# How the controller-manager, scheduler, and proxy find the apiserverKUBE_MASTER="--master=http://centos-master:8080"
    3.4 启动服务
    for SERVICES in kube-proxy kubelet docker; do     systemctl restart $SERVICES    systemctl enable $SERVICES    systemctl status $SERVICES done
    在centos-node01上启动
    [root@centos-minion01 ~]# for SERVICES in kube-proxy kubelet docker; do>     systemctl restart $SERVICES>     systemctl enable $SERVICES>     systemctl status $SERVICES> done
    在centos-minion02上启动
    [root@centos-minion02 kubernetes]# for SERVICES in kube-proxy kubelet docker; do>     systemctl restart $SERVICES>     systemctl enable $SERVICES>     systemctl status $SERVICES> done
    3.5 停止服务
    for SERVICES in kube-proxy kubelet docker; do     systemctl stop $SERVICES done
    4. 检查及确认状态
    #kubectl get nodes
    #kubectl cluster-info
    我们看到2个节点都正常启动。
    [root@CentOS7 yum.repos.d]# kubectl get nodes
    NAME LABELS STATUS AGE 127.0.0.1 kubernetes.io/hostname=127.0.0.1 Ready 15d centos7-1 kubernetes.io/hostname=centos7-1 Ready 4m centos7-2 kubernetes.io/hostname=centos7-2 Ready 4m [root@CentOS7 yum.repos.d]# kubectl cluster-info Kubernetes master is running at http://localhost:8080
  • 相关阅读:
    简单的验证码;在一个数组中随即打印出4个不重复的字母
    数据类型
    java语法基础
    mac 开机运行脚本
    【mac】 搭建java环境
    mac 复制文件到NTFS格式的移动硬盘
    JAVA学习日报 8.19
    JAVA学习日报 8.20
    (VI)事务:Spring 事务管理
    (VI)事务:Spring 事务细节
  • 原文地址:https://www.cnblogs.com/dongdongwq/p/5481246.html
Copyright © 2011-2022 走看看