记录下ubuntu部署K8S集群遇到的各种坑【贰】(非教程)
接下来用yaml来做开始在子节点查看pod时一直报错原来需要和master关联yaml格式问题格式1sudo scp -r /etc/kubernetes/admin.conf ubuntu@170.106.50.78:/etc/kubernetes/admin.confecho “export KUBECONFIG=/etc/kubernetes/admin.conf” >> ~/.
·
接下来用yaml来做
开始在子节点查看pod时一直报错
原来需要和master关联
yaml格式问题
格式1
sudo scp -r /etc/kubernetes/admin.conf ubuntu@170.106.50.78:/etc/kubernetes/admin.conf
echo “export KUBECONFIG=/etc/kubernetes/admin.conf” >> ~/.bash_profile
#source ~/.bash_profile
#source ~/.bashrc
source /etc/profile
执行kubectl create -f 报错
error: error validating "nginx-deployment.yaml": error validating data: [ValidationError(Deployment.spec.template.metadata.labels): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.labels: got "string", expected "map"
是因为我们yaml里没有写空格,没空格会成为string
app: nginx
格式2
error: error validating "nginx-deployment.yaml": error validating data: [ValidationError(Deployment.spec.template.spec.containers[1].ports): invalid type for io.k8s.api.core.v1.Container.ports: got "map", expected "array"
原因为如下,前者正确,后者错误。
ports:
- containerPort: 80
ports:
containerPort: 80
格式3
error: error validating "nginx-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.containers[1]): missing required field "name" in io.k8s.api.core.v1.Container; if you choose to ignore these errors, turn validation off with --validate=false
name 和 image是同级的,我开始写错了(下图正确)
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
可算起来了
root@VM-0-7-ubuntu:~# kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-rtjdg 1/1 Running 0 2m
nginx-deployment-5d59d67564-stt9v 1/1 Running 0 2m
这个是看系统下pod的状态。
root@VM-0-12-ubuntu:~# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-74ff55c5b-9dq5n 1/1 Running 0 6h28m
coredns-74ff55c5b-g44sh 1/1 Running 0 6h28m
etcd-vm-0-12-ubuntu 1/1 Running 0 6h28m
kube-apiserver-vm-0-12-ubuntu 1/1 Running 0 6h28m
kube-controller-manager-vm-0-12-ubuntu 1/1 Running 0 6h28m
kube-proxy-2z68q 1/1 Running 0 6h28m
kube-proxy-brnlv 1/1 Running 0 6h2m
kube-scheduler-vm-0-12-ubuntu 1/1 Running 0 6h28m
weave-net-7gnc5 2/2 Running 1 6h16m
weave-net-szg6g 2/2 Running 0 6h2m
看下pod具体信息,还有event来做debug
kubectl describe pod nginx-deployment-5d59d67564-stt9v
我尝试换了个nginx版本,在yaml里,结果貌似没这个版本,pull不到。
就是这点小心思:
root@VM-0-7-ubuntu:~# kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-rtjdg 1/1 Running 0 13m
nginx-deployment-5d59d67564-stt9v 1/1 Running 0 13m
nginx-deployment-5dcb78cd58-zg8wl 0/1 ErrImagePull 0 12s
root@VM-0-7-ubuntu:~# kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-rtjdg 1/1 Running 0 15m
nginx-deployment-5d59d67564-stt9v 1/1 Running 0 15m
nginx-deployment-64c9d67564-ld5bz 0/1 ContainerCreating 0 5s
root@VM-0-7-ubuntu:~# kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-rtjdg 1/1 Terminating 0 15m
nginx-deployment-5d59d67564-stt9v 1/1 Running 0 15m
nginx-deployment-64c9d67564-ld5bz 1/1 Running 0 11s
nginx-deployment-64c9d67564-mtsz4 0/1 ContainerCreating 0 1s
root@VM-0-7-ubuntu:~# kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-rtjdg 0/1 Terminating 0 15m
nginx-deployment-5d59d67564-stt9v 1/1 Running 0 15m
nginx-deployment-64c9d67564-ld5bz 1/1 Running 0 12s
nginx-deployment-64c9d67564-mtsz4 0/1 ContainerCreating 0 2s
root@VM-0-7-ubuntu:~# kubectl get pods -l app=nginx
NAME READY STATUS RESTARTS AGE
nginx-deployment-5d59d67564-rtjdg 0/1 Terminating 0 15m
nginx-deployment-5d59d67564-stt9v 1/1 Running 0 15m
nginx-deployment-64c9d67564-ld5bz 1/1 Running 0 15s
nginx-deployment-64c9d67564-mtsz4 0/1 ContainerCreating 0 5s
接下来修改volumn
Pod 中的容器,使用的是 volumeMounts 字段来声明自己要挂载哪个 Volume,并通过 mountPath 字段来定义容器内的 Volume 目录,比如:/usr/share/nginx/html。
隐式 Volume, 不显式声明宿主机目录的 Volume: spec.volumes.emptyDir: {}
显示 Volume: 宿主机挂载目录
spec.volumes.hostPath.path: “/var/data”
进去看看,然后删了deployment。
kubectl exec -it nginx-deployment-748c6fff66-8nllh -- /bin/bash
kubectl delete -f nginx-deployment.yaml
更多推荐
已为社区贡献1条内容
所有评论(0)