###查看kubernetes状态
```
kubectl get pods -A #查看相关状态
kubectl get cs #查看k8s的ready状态
kubectl get node #查看k8s节点状态
kubectl -n kube-system get service kubernetes-dashboard #获取端口信息
```
###运维事项
```
kubectl get pods --all-namespaces 获取状态
journalctl -f -u kubelet.service 查看 kubernetes 日志
kubectl apply -f 部署某个组件
kubectl delete 删除某个组件
kubectl get node 获取所有 节点状态
kubectl describe pod kubernetes-dashboard-7d75c474bb-zvc85 -n kube-system
查看 pod 的状态的原因
kubectl logs -f kubernetes-dashboard-7d75c474bb-zvc85 -n kube-system 查看容
器日志
```
###初始化
```
kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=172.16.0.0/16 --apiserver-advertise-address=192.168.1.239
#添加k8s节点
kubeadm join 192.168.1.239:6443 --token mcpg7g.hosgnl6ljwconxxe
--discovery-token-ca-cert-hash sha256:864cf0a1b8ee307a557f780ef30856278898dbe36259575699134d5389d9e935
#安装
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#获取pods状态
kubectl get pods coredns-5c98db65d4-6hbhd -n kube-system -o yaml
kubectl get pods coredns-5c98db65d4-6hbhd --namespace=kube-system -o yaml | grep resources
###初始化 获取pods状态 查看日志 按照yaml删除k8s节点
sudo kubeadm init --kubernetes-version=v1.15.0 --apiserver-advertise-address=192.168.1.239 --pod-network-cidr=192.168.0.0/16
kubectl get pods --all-namespaces
kubectl get node
journalctl -f -u kubelet.service 日志
kubectl delete rbac-kdd.yaml
kubectl delete calico.yaml
kubectl delete pod calico-node-zplqs -n kube-system
kubectl describe pod kubernetes-dashboard-7d75c474bb-zvc85 -n kube-system
kubectl logs -f kube-apiserver-server -n kube-system
kubectl delete -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '
')"
kubectl delete -f calico.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml
```
###kubernetes的安装
```
1.机器安装准备
关闭selinux,防火墙、虚拟内存(所有节点执行)
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
关闭selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
编辑文件
swapoff -a
编辑 /etc/fstab
设置ip6
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum update
yum install docker -y
systemctl start docker
systemctl enable docker
vi /etc/docker/daemon.json
{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://reg-mirror.qiniu.com"
]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
docker info 验证
k8s 安装
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=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
exclude=kube*
EOF
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
kubeadm config images list
k8s 加速器
#!/bin/bash
images=(
kube-apiserver:v1.15.0
kube-controller-manager:v1.15.0
kube-scheduler:v1.15.0
kube-proxy:v1.15.0
pause:3.1
etcd:3.3.10
coredns:1.3.1
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
done
kubeadm init --kubernetes-version v1.15.0 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
允许master 节点运行node
kubectl taint nodes --all node-role.kubernetes.io/master-node/kube untainted
kubeadm join 192.168.1.116:6443 --token plrite.69a1a1jwrb7bjonb --discovery-token-ca-cert-hash sha256:91af313ecdf8f14832e0cc199bc4576af58b6c6f609270904d10c377326db1a3 --ignore-preflight-errors=Swap
docker pull quay.io/coreos/flannel:v0.11.0-amd64
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') 生成令牌
```