K8S安装

1.每个节点安装k8s kubelet kubeadm kubectl,注意与docker版本是否兼容

sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
sudo apt update

查看源中的软件版本
sudo apt-cache madison kubelet
sudo apt install kubelet=1.14.0-00 kubeadm=1.14.0-00 kubectl=1.14.0-00

2.master节点列出需要的镜像

kubeadm config images list

k8s.gcr.io/kube-apiserver:v1.14.0
k8s.gcr.io/kube-controller-manager:v1.14.0
k8s.gcr.io/kube-scheduler:v1.14.0
k8s.gcr.io/kube-proxy:v1.14.0
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1

3.需要翻墙,所以采用镜像下载,然后重新tag

docker pull mirrorgooglecontainers/kube-apiserver:v1.14.0
docker pull mirrorgooglecontainers/kube-controller-manager:v1.14.0
docker pull mirrorgooglecontainers/kube-scheduler:v1.14.0
docker pull mirrorgooglecontainers/kube-proxy:v1.14.0
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd:3.3.10
docker pull coredns/coredns:1.3.1

docker tag mirrorgooglecontainers/kube-apiserver:v1.14.0 k8s.gcr.io/kube-apiserver:v1.14.0
docker tag mirrorgooglecontainers/kube-controller-manager:v1.14.0 k8s.gcr.io/kube-controller-manager:v1.14.0
docker tag mirrorgooglecontainers/kube-scheduler:v1.14.0 k8s.gcr.io/kube-scheduler:v1.14.0
docker tag mirrorgooglecontainers/kube-proxy:v1.14.0 k8s.gcr.io/kube-proxy:v1.14.0
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1

4.初始化Kubernetes

sudo kubeadm init –kubernetes-version=v1.14.0 –pod-network-cidr=10.244.0.0/16

–kubernetes-version 用来指定版本
–pod-network-cidr 用于后期采用flannel作为网络组建而准备
–apiserver-advertise-address 如果机器上只有单个网卡,可以不进行指定

[ERROR Swap]: running with swap on is not supported. Please disable swap
关闭swap

禁用命令
sudo swapoff -a
启用命令
sudo swapon -a
查看交换分区的状态
sudo free -m

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 172.16.121.6:6443 –token d1m708.8w7qwnomcecapizk
–discovery-token-ca-cert-hash sha256:01e71d90ca6e7ca5e9359519d1eb42d95c8783c764a53f6048697c586042586f

6.安装网络插件flannel

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

kubectl get cs检查

7.节点安装

 加载内核模块
sudo modprobe ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh

8.节点加入

kubeadm join 172.16.121.6:6443 –token d1m708.8w7qwnomcecapizk
–discovery-token-ca-cert-hash sha256m:01e71d90ca6e7ca5e9359519d1eb42d95c8783c764a53f6048697c586042586f

[WARNING IsDockerSystemdCheck]: detected “cgroupfs” as the Docker cgroup driver. The recommended driver is “systemd”. Please follow the guide at https://kubernetes.io/docs/setup/cri/
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR Swap]: running with swap on is not supported. Please disable swap
关闭swap
sudo swapoff -a
修改cgroup
vim /etc/default/kubelet
KUBELET_EXTRA_ARGS=–cgroup-driver=cgroupfs
systemctl daemon-reload
systemctl restart kubelet

9.节点删除

在master

kubectl drain –delete-local-data –force –ignore-daemonsets
kubectl delete node

然后使用
节点
kubeadm reset

10.journalctl -f -u kubelet 查看日志

kubectl logs -f coredns-99b9bb8bd-47mvf -n kube-system
kubectl get pods -n kube-system

11.配置dashborad

https://blog.csdn.net/AtlanSI/article/details/88544500

master
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

所有node节点上
docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1

docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1

kubectl get pods -n kube-system 查看

[root@C7-1 ~]# kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 53/UDP,53/TCP 15d
kubernetes-dashboard ClusterIP 10.106.249.245 443/TCP 10m

[root@C7-1 ~]# kubectl patch svc kubernetes-dashboard -p ‘{“spec”:{“type”:”NodePort”}}’ -n kube-system

[root@C7-1 ~]# kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 53/UDP,53/TCP 15d
kubernetes-dashboard NodePort 10.106.249.245 443:30115/TCP 147m

kubernetes-dashboard NodePort 10.99.200.36 443:32357/TCP 98m

12.Forwarding loop detected in “.” zone. Exiting. See

修改/etc/resolve.conf nameserver 114.114.114.114

kubectl delete pod coredns-fb8b8dccf-7vqfw -n kube-system 删除节点