k8s安装
2021-08-15 本文已影响0人
taobao
安装kubernetes-dashboard
github地址:https://github.com/kubernetes/dashboard
//安装
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
//开启访问通道
kubectl proxy
//访问地址
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
//获取token
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/kubernetes-dashboard -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
//如果访问提示 "services "kubernetes-dashboard" not found"
//查看安装状态 READY 1/1 说明就装好了 ,如果是0/1 那是还没有装好,国内网速原因,我是10分钟左右就装好了
kubectl get pods --all-namespaces
// NAME为 kubernetes-dashboard-*的节点
//卸载
//简单方式
kubectl delete -f kubernetes-dashboard.yaml
//查出全部相关
kubectl get secret,sa,role,rolebinding,services,deployments --namespace=kubernetes-dashboard|grep dashboard
//逐个删除各类型 具体名字需要根据上一步结果获取
kubectl delete deployment kubernetes-dashboard --namespace=kube-system
kubectl delete service kubernetes-dashboard --namespace=kube-system
kubectl delete role kubernetes-dashboard-minimal --namespace=kube-system
kubectl delete rolebinding kubernetes-dashboard-minimal --namespace=kube-system
kubectl delete sa kubernetes-dashboard --namespace=kube-system
kubectl delete secret kubernetes-dashboard-certs --namespace=kube-system
kubectl delete secret kubernetes-dashboard-key-holder --namespace=kube-system
指令
//查看全部pods
kubectl get pods --all-namespaces
//删除pod
kubectl delete pod prometheus-tim-3864503240-rwpq5 -n kube-system
//获取系统组件状态
kubectl get -n kube-system all
//服务状态监测
curl -k https://localhost:6443/healthz
部署nginx应用检查集群是否有问题
//创建nginx应用
kubectl create deployment nginx --image=nginx
//输出 deployment.apps/nginx created
//暴露服务端口
kubectl expose deployment nginx --port=80 --type=NodePort
//输出 service/nginx exposed
//检查nginx pod及服务的状态
kubectl get pod,svc -o wide
//访问nginx服务 域名要做硬解析,端口来自上一步返回
curl docker-desktop:30780
//使用本地镜像 先创建,然后改yaml配置 imagePullPolicy: Never
kubectl create deployment mysql --image=mysql
// docker run -e参数 -env 写法如下:
spec:
containers:
- name: mysql
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: '123456'
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Never
错误排查
//获取异常的容器
kubectl get pods -n kube-system | grep -v Running
//查看原因 kubernetes-dashboard-65ff5d4cc8-vfpcq 为异常容器名称
kubectl describe pod kubernetes-dashboard-65ff5d4cc8-vfpcq -n kube-system
k8s services暴露多端口
Servers/yaml文件
spec:
ports:
- name: amqp1
protocol: TCP
port: 5671
targetPort: 5671
nodePort: 32163
- name: amqp2
protocol: TCP
port: 5672
targetPort: 5672
nodePort: 32164
- name: epmd
protocol: TCP
port: 4369
targetPort: 4369
nodePort: 32165
- name: ed
protocol: TCP
port: 25672
targetPort: 25672
nodePort: 32166
- name: stomp1
protocol: TCP
port: 15691
targetPort: 15691
nodePort: 32167
- name: stomp2
protocol: TCP
port: 15692
targetPort: 15692
nodePort: 32168
k8s优先从本地拉取镜像
在 deployment 中可以设置镜像拉取策略 imagePullPolicy 为 IfNotPresent(如果本地不存在则拉取仓库中的)或者设置为 Never(不从仓库中拉取镜像,只用本机的)
如果希望每次都拉取最新的镜像,任选其一:
imagePullPolicy 设置为 Always
省略 imagePullPolicy,并使用 :latest 作为要使用的镜像的标签
spec:
containers:
- name: query-ip
image: XXX
imagePullPolicy: IfNotPresent
Kafka容器 wurstmeister/kafka k8s中启动失败
ERROR: missing mandatory config: KAFKA_ZOOKEEPER_CONNECT
解决方案:追加zookeeper的参数
参考地址:https://www.cnblogs.com/lenmom/p/10775941.html
docker run -d --name kafka -p 9092:9092 \
-e KAFKA_ADVERTISED_HOST_NAME=kafka \
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_ADVERTISED_PORT=9092 \
-e KAFKA_BROKER_ID=1 \
-e KAFKA_LISTENERS=PLAINTEXT://:9092 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://:9092 \
-e KAFKA_CREATE_TOPICS="stream-in:2:1,stream-out:2:1" \
--link zookeeper wurstmeister/kafka:1.1.0
rabbitmq启动管理页面
./rabbitmq-plugins enable rabbitmq_management
// 配置
command:
- /bin/sh
- '-c'
- '--'
args:
- rabbitmq-plugins enable rabbitmq_management