k8s 集群部署 yum 安装

##k8s yum 安装
 
###环境准备    centos7-x86_64
cat /etc/hosts
10.0.0.67 k8s-master01
10.0.0.68 k8s-node01
10.0.0.62 k8s-node02

swapoff -a
systemctl stop firewalld && systemctl disable firewalld
yum -y install ntpdate
ntpdate ntp1.aliyun.com
hwclock
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
vim kubernetes.repo
[kubernetes]
name=kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1

wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
rpm --import rpm-package-key.gpg
scp CentOS-Base.repo docker-ce.repo kubernetes.repo k8s-node01:/etc/yum.repos.d/
scp CentOS-Base.repo docker-ce.repo kubernetes.repo k8s-node02:/etc/yum.repos.d/

yum -y install docker-ce kubelet kubeadm kubectl
cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://mfcnzmmf.mirror.aliyuncs.com"],
  "data-root": "/data/docker",
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}

systemctl start docker&&systemctl enable docker
docker info

echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables

rpm -ql kubelet
    /etc/kubernetes/manifests  #清单目录
    /etc/sysconfig/kubelet   #配置文件
    /etc/systemd/system/kubelet.service  
    /usr/bin/kubelet   #主程序
systemctl enable kubelet

vim pullimage.sh
    #!/bin/bash
    K8S_VERSION=v1.15.0
    ETCD_VERSION=3.2.18
    #ETCD_VERSION=3.3.10
    DASHBOARD_VERSION=v1.8.3
    FLANNEL_VERSION=v0.10.0-amd64
    DNS_VERSION=1.3.1
    PAUSE_VERSION=3.1
    # 基本组件
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:$ETCD_VERSION
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:$PAUSE_VERSION
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION
    # 网络组件
    docker pull quay.io/coreos/flannel:$FLANNEL_VERSION
    # 修改tag
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION k8s.gcr.io/kube-apiserver:$K8S_VERSION
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION k8s.gcr.io/kube-controller-manager:$K8S_VERSION
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION k8s.gcr.io/kube-scheduler:$K8S_VERSION
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION k8s.gcr.io/kube-proxy:$K8S_VERSION
    #docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:$ETCD_VERSION k8s.gcr.io/etcd:$ETCD_VERSION
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:3.3.10 k8s.gcr.io/etcd:3.3.10
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:$PAUSE_VERSION k8s.gcr.io/pause:$PAUSE_VERSION
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION k8s.gcr.io/coredns:$DNS_VERSION
    
 #以上,所有节点的环境
    
###master    
    
kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
 #如果报哪个包错误,就重新下载对应的包和版本,然后重新执行;
 #成功会有如下提示


    Your Kubernetes control-plane has initialized successfully!

    To start using your cluster, you need to run the following as a regular user:

      mkdir -p $HOME/.kube
      sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
      sudo chown $(id -u):$(id -g) $HOME/.kube/config

    You should now deploy a pod network to the cluster.
    Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
      https://kubernetes.io/docs/concepts/cluster-administration/addons/

    Then you can join any number of worker nodes by running the following on each as root:

    kubeadm join 10.0.0.67:6443 --token v116o2.rg2n6pqfm44n2phx \
    --discovery-token-ca-cert-hash sha256:62a203610a2a71ddfc27da68fbb2a1053687945daedc3e51cb771246e6ae80d0 

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
 #检查组件
kubectl get cs
 #查看节点
kubectl get nodes
 #
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# curl -sSL "https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml?raw=true" | kubectl create -f -

docker images
 #查看pod运行情况
kubectl get pods -n kube-system

###node01

kubeadm join 10.0.0.67:6443 --token v116o2.rg2n6pqfm44n2phx \
--discovery-token-ca-cert-hash sha256:62a203610a2a71ddfc27da68fbb2a1053687945daedc3e51cb771246e6ae80d0

###node02

kubeadm join 10.0.0.67:6443 --token v116o2.rg2n6pqfm44n2phx \
--discovery-token-ca-cert-hash sha256:62a203610a2a71ddfc27da68fbb2a1053687945daedc3e51cb771246e6ae80d0

###master

在master服务器上可以查节点信息
kubectl get nodes
kubectl get pods -n kube-system -o wide

###kubernetes dashboard
 #wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml  #此链接的yaml文件已废 404
 #亲测,此链接的yaml文件可用 https://www.cnblogs.com/qinghe123/p/10329625.html
 #本地文件位置: E:\mynar\文档\兆信股份\软件\k8s\kubernetes-dashboard.yaml
 #需要修改镜像地址和nodePort对应端口
vim kubernetes-dashboard.yaml
    image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.0
    nodePort: 30090
    
 #拉去镜像每个节点都执行 
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.0

kubectl create -f kubernetes-dashboard.yaml

kubectl get pods -n kube-system -o wide|grep kubernetes-dashboard
    kubernetes-dashboard-58786fd646-mp2m2   1/1     Running   0          165m    10.244.1.2   k8s-node01                   
 #看到运行在node01节点上,在浏览器输入 node01的真实ip+端口(10.0.0.68:30090) 进行访问
 

你可能感兴趣的:(devops)