标签 kubernetes 下的文章

CentOS 7 使用kubeadm安装kubernetes1.7.2集群

更新时间

ntpdate cn.pool.ntp.org
hwclock -w

此处建议将更新时间加入到任务计划中定时执行, k8s集群内时间不一致是会出问题…

  1. 添加kubernetes仓库源

    cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    name=Kubernetes
    baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
            https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
    EOF
    
  2. 更新&&禁用防火墙

    yum update -y
    systemctl disable firewalld && systemctl stop firewalld && systemctl status firewalld
    
  3. 开启sysctl参数

    net.bridge.bridge-nf-call-iptables = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    
  4. 安装brctl

    yum install bridge-utils -y
    
  5. 安装kubeadm等k8s组件

    yum install kubelet kubeadm kubectl kubernetes-cni -y
    
  6. 安装docker

    yum install docker # 1.12.6版本
    
  7. 安装k8s

    kubeadm init --pod-network-cidr=10.244.0.0/16 --kubernetes-version v1.7.2
    
  8. 创建网络

    kubectl create -f \
    https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel-rbac.yml
    kubectl create -f  \
    https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    
  9. 修改hairpin-mode 让service 可以访问自己

    临时解决:

    /sys/class/net/cni0/brif
    
    for intf in $(ip link list | grep veth | cut -f2 -d:|awk -F "@" '{print $1}'|awk -F " " '{print $1}') ; do brctl hairpin cni0 $intf on; done
    
    

    方法一:

    # 此方法在网络插件重新创建后会失效.
    
    /etc/cni/net.d/10-flannel.conf
    {
      "name": "cbr0",
      "type": "flannel",
      "delegate": {
        "isDefaultGateway": true,
        "hairpinMode": true
      }
    }
    

    方法二:
    修改ConfigMap
    保存修改后重新创建

    [root@fykbnode-hzba-2 ~]# kubectl get cm/kube-flannel-cfg -n kube-system -o yaml
    apiVersion: v1
    data:
    cni-conf.json: |
    {
      "name": "cbr0",
      "type": "flannel",
      "delegate": {
        "isDefaultGateway": true,
        "hairpinMode": true
      }
    }
    net-conf.json: |
    {
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan"
      }
    }
    kind: ConfigMap
    metadata:
    creationTimestamp: 2017-09-12T11:40:18Z
    labels:
    app: flannel
    tier: node
    name: kube-flannel-cfg
    namespace: kube-system
    resourceVersion: "97"
    selfLink: /api/v1/namespaces/kube-system/configmaps/kube-flannel-cfg
    uid: 26bfe3f8-97af-11e7-9a7e-246e9671187c
    
  10. 测试

kubectl create namespace sock-shop
kubectl create -f https://github.com/microservices-demo/microservices-demo/blob/master/deploy/kubernetes/complete-demo.yaml?raw=true
  1. 网络问题
# 当安装时如果有多次kubeadm reset 情况, 请执行以下三条命令清除网络设置... 不然会造成网络混乱冲突, 导致集群内网络互相不通...
ifconfig  cni0 down
brctl delbr cni0
ip link delete flannel.1