1. 程式人生 > >Kubernetes安裝--Kubeadm

Kubernetes安裝--Kubeadm

Kubeadm安裝Kubernetes環境總結:

Kubernetes服務架構採用Mater-Slave,不考慮高可用,一般採用一個Master節點和多個Slave節點,這裡採用1Master和2Slave節點

首先這裡採用Vmware來安裝三臺Linux作業系統,網路設定為NAT模式

Master和Slave均要操作

1.配置好各節點hosts檔案

K8smaster    192.168.3.3

K8snode1    192.168.3.4

K8snode2    192.168.3.5

2.關閉系統防火牆

Systemctl  stop    firewalld.service

Systemctl  disable  firewalld.service

3.關閉Selinux

Vim  /etc/selinux/config

SELINUX=disabled

4.關閉swap

Swapoff  -a

5.配置系統核心引數使流過網橋的流量也進入iptables/netfilter框架中

Vim 在/etc/sysctl.conf中新增以下配置:

net.bridge.bridge-nf-call-iptables = 1

net.bridge.bridge-nf-call-ip6tables = 1

sysctl –p

重啟

6.配置阿里K8S YUM源

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

[kubernetes]

name=Kubernetes

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

enabled=1

gpgcheck=0

EOF

yum -y install epel-release

yum clean all

yum makecache

7.安裝kubeadm和相關工具包

yum -y install docker kubelet kubeadm kubectl kubernetes-cni

8.啟動Docker與kubelet服務

systemctl enable docker && systemctl start docker

systemctl enable kubelet && systemctl start kubelet

9.配置加速映象

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'

{

  "registry-mirrors": ["https://99b9e5v9.mirror.aliyuncs.com"]

}

EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

10.下載K8S相關映象

#!/bin/bash

images=(kube-proxy-amd64:v1.10.0 kube-scheduler-amd64:v1.10.0 kube-controller-manager-amd64:v1.10.0 kube-apiserver-amd64:v1.10.0

etcd-amd64:3.1.12 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.8 k8s-dns-kube-dns-amd64:1.14.8

k8s-dns-dnsmasq-nanny-amd64:1.14.8)

for imageName in ${images[@]} ; do

  docker pull keveon/$imageName

  docker tag keveon/$imageName k8s.gcr.io/$imageName

  docker rmi keveon/$imageName

done

11.master節點操作如下

初始化安裝K8S Master

kubeadm init --kubernetes-version=v1.10.0 --pod-network-cidr=10.244.0.0/16

配置kubectl認證資訊

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

安裝flannel網路

mkdir -p /etc/cni/net.d/

cat <<EOF> /etc/cni/net.d/10-flannel.conf

{

“name”: “cbr0”,

“type”: “flannel”,

“delegate”: {

“isDefaultGateway”: true

}

}

EOF

mkdir /usr/share/oci-umount/oci-umount.d -p

mkdir /run/flannel/

cat <<EOF> /run/flannel/subnet.env

FLANNEL_NETWORK=10.244.0.0/16

FLANNEL_SUBNET=10.244.1.0/24

FLANNEL_MTU=1450

FLANNEL_IPMASQ=true

EOF

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

12.Node節點:

執行1-10步驟

加入master節點

kubeadm join 192.168.3.3:6443 --token jw07fw.108yecqmxs2vpxp8 --discovery-token-ca-cert-hash sha256:a8af61e79dfdecae8055fc82ece3547655d9aa57e34cc83f6f3fb4b54711f09f

 

其他操作

master重啟

kubeadm reset

swapoff –a

kubeadm init --kubernetes-version=v1.10.0 --pod-network-cidr=10.244.0.0/16

node重啟

kubeadm reset

swapoff –a

kubeadm join

 

kubectl管理:

# 檢視節點狀態

kubectl get nodes

kubectl describe node k8snode1

# 檢視pods狀態

kubectl get pods --all-namespaces

# 檢視K8S叢集狀態

kubectl get cs

 

DNS服務搭建

配置好各主機/etc/hosts

驗證DNS服務:

kubectl run curl --image=radial/busyboxplus:curl -i --tty

nslookup kubernetes.default

kubectl delete deploy curl