k8s 集群搭建

一,环境介绍

  master node1 node2
IP 192.168.0.164 192.168.0.165 192.168.0.167
环境 centos 7 centos 7 centos 7

二,配置安装

   三台节点操作实例:"

   01,配置yum源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]

name=Kubernetes

baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64

enabled=1

gpgcheck=0

repo_gpgcheck=0

gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg

        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

    02,安装ETCD

yum install -y etcd

     节点加入:

master节点加入:(IP 192.168.1.164)

etcd -name infra1 -initial-advertise-peer-urls http://192.168.0.164:2380 -listen-peer-urls http://192.168.0.164:2380 -listen-client-urls http://192.168.0.164:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.0.164:2379 -initial-cluster-token etcd-cluster-1 -initial-cluster infra1=http://192.168.0.164:2380,infra2=http://192.168.0.165:2380,infra3=http://192.168.0.167:2380 -initial-cluster-state new

node1节点加入:(IP 192.168.1.165)

etcd -name infra2 -initial-advertise-peer-urls http://192.168.0.165:2380 -listen-peer-urls http://192.168.0.165:2380 -listen-client-urls http://192.168.0.165:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.0.165:2379 -initial-cluster-token etcd-cluster-1 -initial-cluster infra1=http://192.168.0.164:2380,infra2=http://192.168.0.165:2380,infra3=http://192.168.0.167:2380 -initial-cluster-state new

node2节点加入:(IP 192.168.1.167)

etcd -name infra3 -initial-advertise-peer-urls http://192.168.0.167:2380 -listen-peer-urls http://192.168.0.167:2380 -listen-client-urls http://192.168.0.167:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.0.167:2379 -initial-cluster-token etcd-cluster-1 -initial-cluster infra1=http://192.168.0.164:2380,infra2=http://192.168.0.165:2380,infra3=http://192.168.0.167:2380 -initial-cluster-state new

      ECTD节点检查:

  启动后另起一个窜口输入命令

 etcdctl cluster-health

    说明成功

      节点管理:(更改ip即可完成多台)

      vim /usr/lib/systemd/system/etcd.service

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/root
ExecStart=etcd -name infra1 -initial-advertise-peer-urls http://192.168.0.164:2380 -listen-peer-urls http://192.168.0.164:2380 -listen-client-urls http://192.168.0.164:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.0.164:2379 -initial-cluster-token etcd-cluster-1 -initial-cluster infra1=http://192.168.0.164:2380,infra2=http://192.168.0.165:2380,infra3=http://192.168.0.167:2380 -initial-cluster-state new
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

    

#!/bin/bash
echo ‘################ Prerequisites...‘
systemctl stop firewalld
systemctl disable firewalld
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd

echo ‘################ Installing flannel...‘
#安装flannel
yum install flannel -y

echo ‘################ Add subnets for flannel...‘
A_SUBNET=172.17.0.0/16
B_SUBNET=192.168.0.0/16
C_SUBNET=10.254.0.0/16

FLANNEL_SUBNET=$A_SUBNET
SERVICE_SUBNET=$B_SUBNET
OCCUPIED_IPs=(`ifconfig -a | grep ‘inet ‘ | cut -d ‘:‘ -f 2 |cut -d ‘ ‘ -f 1 | grep -v ‘^127‘`)
for ip in ${OCCUPIED_IPs[@]};do
    if [ $(ipcalc -n $ip/${A_SUBNET#*/}) == $(ipcalc -n ${A_SUBNET}) ];then
        FLANNEL_SUBNET=$C_SUBNET
        SERVICE_SUBNET=$B_SUBNET
        break
    fi
    if [ $(ipcalc -n $ip/${B_SUBNET#*/}) == $(ipcalc -n ${B_SUBNET}) ];then
        FLANNEL_SUBNET=$A_SUBNET
        SERVICE_SUBNET=$C_SUBNET
        break
    fi
    if [ $(ipcalc -n $ip/${C_SUBNET#*/}) == $(ipcalc -n ${C_SUBNET}) ];then
        FLANNEL_SUBNET=$A_SUBNET
        SERVICE_SUBNET=$B_SUBNET
        break
    fi
done

while ((1));do
    sleep 2
    etcdctl cluster-health
    flag=$?
    if [ $flag == 0 ];then
etcdctl mk /coreos.com/network/config ‘{"Network":"‘${FLANNEL_SUBNET}‘"}‘
        break
    fi
done

echo ‘################ Starting flannel...‘
echo -e "FLANNEL_ETCD=\"http://192.168.0.164:2379,http://192.168.0.165:2379,http://192.168.0.167:2379\"
FLANNEL_ETCD_KEY=\"/coreos.com/network\"" > /etc/sysconfig/flanneld
systemctl enable flanneld
systemctl start flanneld

echo ‘################ Installing K8S...‘
yum -y install kubernetes
echo ‘KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBELET_PORT="--kubelet_port=10250"
KUBE_ETCD_SERVERS="--etcd_servers=http://192.168.0.164:2379,http://192.168.0.165:2379,http://192.168.0.167:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=‘${SERVICE_SUBNET}‘"
KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""‘ > /etc/kubernetes/apiserver

echo ‘################ Start K8S components...‘
for SERVICES in kube-apiserver kube-controller-manager kube-scheduler; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done

#!/bin/bash

echo ‘################ Prerequisites...‘
#关闭firewall 开启ntp时间同步
systemctl stop firewalld
systemctl disable firewalld
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd

#安装kubernetes所需要的几个软件
yum -y install kubernetes docker flannel bridge-utils

#此处使用了一个vip 命名为vip 实际部署时需要替换为你的集群的vip 使用此ip的服务有 kube-master(8080) registry(5000) skydns(53)

echo ‘################ Configuring nodes...‘
echo ‘################ Configuring nodes > Find Kube master...‘
KUBE_REGISTRY_IP="192.168.0.169"
KUBE_MASTER_IP="192.168.0.170"
echo ‘################ Configuring nodes > Configuring Minion...‘
echo -e "KUBE_LOGTOSTDERR=\"--logtostderr=true\"
KUBE_LOG_LEVEL=\"--v=0\"
KUBE_ALLOW_PRIV=\"--allow_privileged=false\"
KUBE_MASTER=\"--master=http://${KUBE_MASTER_IP}:8080\"" > /etc/kubernetes/config
echo ‘################ Configuring nodes > Configuring kubelet...‘
#取每个node机器的eth0的ip作为标识
KUBE_NODE_IP=`ifconfig eth0 | grep "inet " | awk ‘{print $2}‘`

#api_servers 使用master1 master2 master3的ip数组形式
echo -e "KUBELET_ADDRESS=\"--address=0.0.0.0\"
KUBELET_PORT=\"--port=10250\"
KUBELET_HOSTNAME=\"--hostname_override=${KUBE_NODE_IP}\"
KUBELET_API_SERVER=\"--api_servers=http://192.168.0.164:8080,http://192.168.0.165:8080,http://192.168.0.167:8080\"
KUBELET_ARGS=\"--cluster-dns=vip --cluster-domain=k8s --pod-infra-container-image=${KUBE_REGISTRY_IP}:5000/pause:latest\"" > /etc/kubernetes/kubelet

#flannel读取etcd配置信息 为本机的docker0分配ip 保证node集群子网互通
echo ‘################ Configuring flannel...‘
echo -e "FLANNEL_ETCD=\"http://192.168.0.162:2379,http://192.168.0.165:2379,http://192.168.0.167:2379\"
FLANNEL_ETCD_KEY=\"/coreos.com/network\"" > /etc/sysconfig/flanneld

echo ‘################ Accept private registry...‘
echo "OPTIONS=‘--selinux-enabled --insecure-registry ${KUBE_REGISTRY_IP}:5000‘
DOCKER_CERT_PATH=/etc/docker" > /etc/sysconfig/docker

echo ‘################ Start K8S Components...‘
systemctl daemon-reload
for SERVICES in kube-proxy flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done

echo ‘################ Resolve interface conflicts...‘
systemctl stop docker
ifconfig docker0 down
brctl delbr docker0

echo ‘################ Accept private registry...‘
echo -e "OPTIONS=‘--selinux-enabled --insecure-registry ${KUBE_REGISTRY_IP}:5000‘
DOCKER_CERT_PATH=/etc/docker" > /etc/sysconfig/docker

for SERVICES in docker kubelet; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done

原文地址:https://www.cnblogs.com/kingle-study/p/10421290.html

时间: 2024-11-02 16:47:10

k8s 集群搭建的相关文章

K8s集群搭建(kubeadm方案)

K8s集群搭建(kubeadm方案) 1.最少3台CentosA.至少2核CPU+2G内存+20G硬盘B.必须在同一网段本示例中分配为: Master:192.168.20.245 Worker1:192.168.20.167 Worker2:192.168.20.166 2.ip addr确认是否有分配到IPV4地址.没有的话nmtui,Automatically connect打上勾 3.用SSH连接 4.禁用防火墙, systemctl stop firewalld & systemctl

k8s集群搭建

k8s简介 kubernetes,简称K8s,是用8代替8个字符“ubernete”而成的缩写.是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效(powerful),Kubernetes提供了应用部署,规划,更新,维护的一种机制 k8s的资源对象 master kubernetes里的master指的是集群控制节点,在每个kubernetes集群里都需要有一个master来负责真个集群的管理和控制,在master上运行着以下关键进

Kubernetes集群搭建以及部署高可用ingress

k8s服务器 10.10.4.85 master 10.10.4.86 node 10.10.4.87 node 3个服务器都配置好主机名以及hosts配置: k8s集群搭建 在10.10.4.85 上操作,master节点 使用kubeadm工具安装,参考:使用kubeadm安装kubernetes_v1.17.x:https://kuboard.cn/install/install-k8s.htm #curl -sSL https://kuboard.cn/install-script/v1

[k8s]kube-dns/dashboard排错历险记(含sa加载用法/集群搭建)

kube-dns原理 参考: 组件架构看这个就够了 http://cizixs.com/2017/04/11/kubernetes-intro-kube-dns 设置细节看这个就够了 http://blog.fleeto.us/translation/configuring-private-dns-zones-and-upstream-nameservers-kubernetes busybox你的忠实实验伴侣 命令看这里: https://kubernetes.io/docs/concepts

.net core i上 K8S(一)集群搭建

1.前言 以前搭建集群都是使用nginx反向代理,但现在我们有了更好的选择——K8S.我不打算一上来就讲K8S的知识点,因为知识点还是比较多,我打算先从搭建K8S集群讲起,我也是在搭建集群的过程中熟悉了K8S的一些概念,希望对大家有所帮助.K8S集群的搭建难度适中,网上有很多搭建k8s的教程,我搭建的过程中或多或少遇到一些问题,现在就把我总结完的教程给大家总结一下.这里主要讲通过二进制包安装K8S 2.集群组件介绍 节点 ip 组件 master 192.168.8.201 etcd:存储集群节

kubernetes (K8S) 集群的搭建方式

kubernetes (K8S) 集群的搭建方式有两种: 守护进程模式和容器模式 (请注意看图,不一样的) 容器的编排管理工具,当然推荐使用容器来部署了.不过容器镜像是在 Google 云上的,需要各位各显神通了. container部署: systemd模式部署: 原文地址:https://www.cnblogs.com/liuxgcn/p/11154259.html

ubuntu18.04搭建k8s集群

上个月为小组搭建一个k8s的nvidia gpu集群,在此记录一下,以免以后忘记. 本次搭建采用的ubuntu18.04 server ,docker版本采用的19.03.2,k8s版本是1.15.2. name version ubuntu server 18.04 docker 19.03.2 k8s 1.15.2 搭建集群之前需要安装nvidia显卡驱动,这里就不在赘述如何安装驱动. 集群需要设置固定ip,dns,否则容器可能不能访问外网. 通过shell脚本文件自动安装,install.

搭建K8s集群[无需科学shangwang]

官网:https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl GitHub:https://github.com/kubernetes/kubeadm 使用kubeadm搭建一个3台机器组成的k8s集群,1台master节点,2台worker节点 配置(官方配置要求): - One or more ma

k8s docker集群搭建

?Kubernetes介绍 1.背景介绍 云计算飞速发展 - IaaS - PaaS - SaaS Docker技术突飞猛进 - 一次构建,到处运行 - 容器的快速轻量 - 完整的生态环境 2.什么是kubernetes 首先,他是一个全新的基于容器技术的分布式架构领先方案.Kubernetes(k8s)是Google开源的容器集群管理系统(谷歌内部:Borg).在Docker技术的基础上,为容器化的应用提供部署运行.资源调度.服务发现和动态伸缩等一系列完整功能,提高了大规模容器集群管理的便捷性