在虚拟机折腾K8s
虚拟机系统初始化(Master与Node均需执行)
vim /etc/hosts
10.10.10.100 k8s-master
10.10.10.101 k8s-node1
10.10.10.102 k8s-node2
swapoff -a
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce.x86_64 docker-ce-cli.x86_64 -y
systemctl enable docker.service
systemctl start docker.service
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://bdf5zlvt.mirror.aliyuncs.com"]
}
systemctl daemon-reload
systemctl restart docker.service
安装Kubernetes(Master与Node均需执行)
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
yum install kubelet-1.19.0 kubeadm-1.19.0 kubectl-1.19.0 -y
systemctl enable kubelet.service
systemctl start kubelet.service
echo "source <(kubectl completion bash)" >> ~/.bash_profile
source ~/.bash_profile
kubeadm config images list --kubernetes-version=1.19.0
vim get_image.sh
bash get_image.sh
#!/bin/bash
new_registry=registry.cn-hangzhou.aliyuncs.com/google_containers
old_registry=k8s.gcr.io
arr=(kube-apiserver:v1.19.0 kube-controller-manager:v1.19.0 kube-scheduler:v1.19.0 kube-proxy:v1.19.0 pause:3.2 etcd:3.4.9-1 coredns:1.7.0)
for var in ${arr[@]}
do
docker pull $new_registry/$var
docker tag $new_registry/$var $old_registry/$var
done
docker image ls -a
配置Kubernetes Master(仅在Master节点执行)
kubeadm init --apiserver-advertise-address 10.10.10.100 --pod-network-cidr=10.20.0.0/16 --kubernetes-version 1.19.0
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile
Kube-Flannel网络配置
curl https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml -o kube-flannel.yml
kubectl apply -f kube-flannel.yml
Kube-Dashboard配置
curl https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml -o recommended.yaml
vim recommended.yaml
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30000
selector:
k8s-app: kubernetes-dashboard
---
kubectl apply -f recommended.yaml
netstat -tulnp
kubectl describe secret -n kubernetes-dashboard kubernetes-dashboard-token-72krn
vim recommended.yaml
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
---
kubectl apply -f recommended.yaml
配置Kubernetes Node(仅在Node节点执行)
kubeadm join 10.10.10.100:6443 --token x69j0h.spr9aisuox02xcbj --discovery-token-ca-cert-hash sha256:9291f5085dad5b23caf982a8faf042aa4331d956039c36438f02f0ffb34b7f44
玩转Kubernetes命令
kubectl get nodes/kubectl get node
kubectl get pod --all-namespaces
kubectl get secret
kubectl get secret -n kubernetes-dashboard
kubectl describe secret -n kubernetes-dashboard kubernetes-dashboard-token-72krn
kubectl get pod/kubectl get pods
kubectl get pod -n kubernetes-dashboard
kubectl get pod -n kubernetes-dashboard -o wide
kubectl taint node k8s-master node-role.kubernetes.io/master-
kubectl taint node k8s-master node-role.kubernetes.io/master=""
kubectl get deployment -n kubernetes-dashboard
kubectl describe deployments
kubectl get services/kubectl get service
未完待续…………