pod
#创建ns,先有才能创建pod
[root@node2 pod]# cd /root/myk8s/pod
[root@node2 pod]# cat test-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: myk8s
spec:
containers:
- name: busybox
image: 127.0.0.1/myk8s/busybox
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
[root@node2 pod]# kubectl create ns myk8s
[root@node2 pod]# kubectl get ns
[root@node2 pod]# kubectl create -f test-pod.yaml
[root@node2 pod]# kubectl get pod --namespace=myk8s
#删除容器
[root@node2 pod]# kubectl delete pods busybox --namespace=myk8s
#查看日志
[root@node2 pod]# kubectl logs busybox --namespace=myk8s
#查看pod细节
[root@node2 pod]# kubectl describe pod busybox --namespace=myk8s
#使用edit,修改配置
[root@node2 pod]# kubectl edit ns myk8s
[root@node2 pod]# kubectl edit pod busybox --namespace=myk8s
[root@node2 pod]# vim test-pod.yaml
[root@node2 pod]# kubectl apply -f test-pod.yaml
#修改yaml后,更新pod
[root@node2 pod]# kubectl apply -f nginx-pod.yaml
[root@node2 pod]# kubectl describe pod nginx
[root@node2 pod]# docker pull nginx
#有yaml情况下,重启pending状态pod
[root@node2 pod]# kubectl replace --force -f nginx-pod.yaml
[root@node2 pod]# kubectl logs nginx
#
[root@node2 pod]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
busybox 1/1 Running 0 17m 172.30.2.10 node16 <none> <none>
nginx 1/1 Running 0 2m40s 172.30.1.9 node3 <none> <none>
[root@node2 pod]# curl http://172.30.1.9
[root@node2 pod]# mkdir deployment
[root@node2 deployment]# rz
[root@node2 deployment]# vim nginx-deploy.yaml
[root@node2 deployment]# kubectl create -f nginx-deploy.yaml
#实时查看pod状态变化
[root@node2 ~]# watch -d -n 1 kubectl get pods -o wide
[root@node2 deployment]# vim nginx-deploy.yaml
[root@node2 deployment]# kubectl apply -f nginx-deploy.yaml
[root@node2 ~]# curl 172.30.2.22 -I
[root@node2 ~]# curl 172.30.2.22
[root@node2 ~]# kubectl logs -f nginx-deploy-7848d4b86f-48cqm
[root@node2 service]# kubectl apply -f nginx-svc.yaml
[root@node2 service]# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 24h <none>
nginx-svc NodePort 10.254.55.107 <none> 80:32291/TCP 10s app=nginx
#配置nodeport;访问CLUSTER-IP:port 10.254.55.107:80ok的、 10.254.55.107:32291是不行的、可访方式nodeip:nodeport即10.206.0.2/3/16:32291 都可
[root@node2 myk8s]# kubectl get svc -n default
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 25h
nginx-svc NodePort 10.254.55.107 <none> 80:32291/TCP 5m8s
#删除nodeport配置 即clusterip模式、配置node为11180;访问 10.254.55.107:11180
[root@node2 myk8s]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.254.0.1 <none> 443/TCP 25h
nginx-svc ClusterIP 10.254.55.107 <none> 11180/TCP 10m
#所以IP,有几个层面的。POD IP;POD CLUSTER IP(SERVICE层面);NODE IP(集群NODE节点IP)
#POD IP:PORT
#CLUSTER IP:PORT(未配置NodePort);SERVICE 配置后,即有了 CLUSTER IP
#NODE IP:PORT(配置NodePort)、以及 CLUSTER IP:PORT 均可访问
[root@node3 ~]# systemctl status kubelet.service
[root@node3 ~]# systemctl status kubelet
?
[root@node2 metrics-server0.5.0]# kubectl top pod nginx-deploy-7848d4b86f-24f82
error: Metrics API not available
[root@node2 metrics-server0.5.0]# pwd
/root/metrics-server0.5.0
[root@node2 metrics-server0.5.0]# kubectl apply -f components.yaml
serviceaccount/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
service/metrics-server created
deployment.apps/metrics-server created
[root@node2 metrics-server-0.5.0]# kubectl delete -f ../../kubesphere/components.yaml
[root@node2 metrics-server0.5.0]# wget https://github.com/kubernetes/kubernetes/blob/4e30c058c4f73f8cf543501efaff44700867d7fa/cluster/addons/metrics-server/metrics-server-deployment.yaml
?
|