amy_888 发表于 2018-9-16 07:57:35

centos7 kubernetes安装手册

  安装之前,将三台centos7服务器禁止防火墙,同时需要启动的镜像2台node机器都要保持时间一致,否则pod不能启动
  1 有三台centos7服务器:10.1.1.170(master),10.1.1.169 node1,10.1.1.171 node2
  2 在三台机器上安装ntp服务,以保证所有时间可以同步
  #yum -y install ntp
  #systemctl start ntpd
  #systemctl enable ntpd
  3 在10.1.1.170上安装kubernetes master
  Yum install etcd
  Yum install kubernetes
  Cd /etc/etcd
  Vi etcd.conf,需要注意项:
  ETCD_NAME=default
  ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
  ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
  *   cd /etc/kubernetes/
  * vi apiserver
  # more 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=127.0.0.1"
  KUBE_API_ADDRESS="--address=0.0.0.0"
  # 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://127.0.0.1:2379"
  # Address range to use for services
  KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
  # default admission control policies
  #KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
  KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
  # Add your own!
  KUBE_API_ARGS=""
  * cd /etc/kubernetes
  * vi controller-manager   定义节点
  # more controller-manager
  ###
  # The following values are used to configure the kubernetes controller-manager
  # defaults from config and apiserver should be adequate
  # Add your own!
  KUBE_CONTROLLER_MANAGER_ARGS=""
  KUBELET_ADDRESSES="--machine=10.1.1.169,10.1.1.171"
  *依次启动服务,将服务放入启动目录(etcd\kube-apiserver\kube-controller-manager\kube-scheduler):
  systemctl restart 服务名
  systemctl enable 服务名
  systemctl status 服务名
  * 定义flannel网络配置到etcd,配置被推送到各个minions的flannel网络上
  etcdctl mk /coreos.com/network/config '{"Network":"172.17.0.0/16"}'
  4 在节点(10.1.1.169,10.1.1.171)上进行minions部署
  #yum install flannel
  #yum install kubernetes
  *修改flannel配置文件,以使用etcd服务
  #vi /etc/sysconfig/flanneld
  # more /etc/sysconfig/flanneld
  # Flanneld configuration options
  # etcd url location.Point this to the server where etcd runs
  FLANNEL_ETCD="http://10.1.1.170:2379"
  # etcd config key.This is the configuration key that flannel queries
  # For address range assignment
  FLANNEL_ETCD_KEY="/atomic.io/network"
  # Any additional options that you want to pass
  #FLANNEL_OPTIONS=""
  *配置kubernetes配置文件
  #vi /etc/ kubernetes/config
  # more /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 journal
  KUBE_LOGTOSTDERR="--logtostderr=true"
  # journal message level, 0 is debug
  KUBE_LOG_LEVEL="--v=0"
  # Should this cluster be allowed to run privileged docker containers
  KUBE_ALLOW_PRIV="--allow-privileged=false"
  # How the controller-manager, scheduler, and proxy find the apiserver
  KUBE_MASTER="--master=http://10.1.1.170:8080"
  *配置kubelet服务
  #vi /etc/kubernetes/kubelet
  # more /etc/kubernetes/kubelet
  ###
  # 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=10.1.1.171"
  # The port for the info server to serve on
  KUBELET_PORT="--port=10250"
  # You may leave this blank to use the actual hostname
  KUBELET_HOSTNAME="--hostname-override=10.1.1.171"
  # location of the api-server
  KUBELET_API_SERVER="--api-servers=http://10.1.1.170:8080"
  # pod infrastructure container
  KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
  # Add your own!
  KUBELET_ARGS=""
  *启动服务(kube-proxy\kubylet\docker\flanneld),很奇怪启动flanneld服务时报错,但是过一段时间k8s一切OK
  #systemctl restart 服务
  #system enable 服务
  #systemctl status 服务
  5 将三台机器进行ssh免密码操作:
  #ssh-keygen
  #ssh-copy-id root@10.1.1.171
  #ssh-copy-id root@10.1.1.169
  6 测试kubernetes服务是否正常
  # kubectl get nodes
  NAME         LABELS                              STATUS    AGE
  10.1.1.169   kubernetes.io/hostname=10.1.1.169   Ready   20h
  10.1.1.171   kubernetes.io/hostname=10.1.1.171   Ready   21h
  # kubectl get componentstatuses
  NAME               STATUS    MESSAGE            ERROR
  controller-manager   Healthy   ok                   nil
  scheduler            Healthy   ok                   nil
  etcd-0               Healthy   {"health": "true"}   nil
  kubectl run tomcat --image=tomcat:8.0 --port=8080 --replicas=5
  # kubectl get rc,pods
  CONTROLLER      CONTAINER(S)   IMAGE(S)         SELECTOR      REPLICAS   AGE
  centos7         centos7      centos:7         run=centos7   3          59m
  mysql         mysql          mysql:5.5          run=mysql   7          1h
  tomcat          tomcat         tomcat:8.0         run=tomcat    5          19h
  NAME            READY          STATUS             RESTARTS      AGE
  centos7-asa0g   1/1            Running            15            59m
  centos7-eow3g   0/1            CrashLoopBackOff   16            59m
  centos7-qmslb   0/1            CrashLoopBackOff   12            59m
  mysql-0a5tv   0/1            CrashLoopBackOff   16            1h
  mysql-131lh   0/1            CrashLoopBackOff   16            1h
  mysql-7cj2s   0/1            CrashLoopBackOff   16            1h
  mysql-89h04   0/1            CrashLoopBackOff   16            1h
  mysql-htu4u   0/1            CrashLoopBackOff   16            1h
  mysql-khndm   0/1            CrashLoopBackOff   16            1h
  mysql-uke1c   0/1            CrashLoopBackOff   16            1h
  tomcat-1wwbn    1/1            Running            1             19h
  tomcat-f83z1    1/1            Running            1             19h
  tomcat-fu2qf    1/1            Running            1             19h
  tomcat-l39ih    1/1            Running            1             19h
  tomcat-o647v    1/1            Running            1             19h
  在两台节点上可以发现,一个节点上跑了2个tomcat,一个节点上跑了3个tomcat,一旦一个镜像被删除,则马上会在启动一个新的节点

页: [1]
查看完整版本: centos7 kubernetes安装手册