天天看點

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     <none>           <none>    

 #看到運作在node01節點上,在浏覽器輸入 node01的真實ip+端口(10.0.0.68:30090) 進行通路

繼續閱讀