本章涉及到一些概念 1.首先是Pod,Pod 是一组一个或多个应用程序容器(例如 Docker),包括共享存储(卷), IP 地址和有关如何运行它们的信息。我们在创建deployment的时候。k8s就为我们添加了一个Pod来托管我们的应用。Pod 中的容器共享 IP 地址和端口,始终位于同一位置并且共同调度,并在同一工作节点上的共享上下文中运行 2.工作节点Node,一个 pod 总是运行在 工作节点。工作节点是 Kubernetes 中的参与计算的机器,可以是虚拟机或物理计算机,具体取决于集群。每个工作节点由主节点管理。工作节点可以有多个 pod ,Kubernetes 主节点会自动处理在群集中的工作节点上调度 pod 。 主节点的自动调度考量了每个工作节点上的可用资源。 每个 Kubernetes 工作节点至少运行:
- Kubelet,负责 Kubernetes 主节点和工作节点之间通信的过程; 它管理 Pod 和机器上运行的容器。
- 容器运行时(如Docker)负责从仓库中提取容器镜像,解压缩容器以及运行应用程序。
查看pod
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
kubernetes-bootcamp-fb5c67579-zxj5k 1/1 Running 0 107s
$
查看pod详情
$ kubectl describe pods
Name: kubernetes-bootcamp-fb5c67579-zxj5k
Namespace: default
Priority: 0
Node: minikube/172.17.0.99
Start Time: Tue, 09 Nov 2021 14:43:34 +0000
Labels: app=kubernetes-bootcamp
pod-template-hash=fb5c67579
Annotations: <none>
Status: Running
IP: 172.18.0.2
IPs:
IP: 172.18.0.2
Controlled By: ReplicaSet/kubernetes-bootcamp-fb5c67579
Containers:
kubernetes-bootcamp:
Container ID: docker://e4ab1d2597457188767a42714c0844caaba1239c0721245377bc218a1c70e6cb
Image: gcr.io/google-samples/kubernetes-bootcamp:v1
Image ID: docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 09 Nov 2021 14:43:37 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-852k6 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-852k6:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-852k6
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m41s default-scheduler Successfully assigned default/kubernetes-bootcamp-fb5c67579-zxj5k to minikube
Normal Pulled 2m39s kubelet Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine
Normal Created 2m39s kubelet Created container kubernetes-bootcamp
Normal Started 2m38s kubelet Started container kubernetes-bootcamp
$
程序内的任何标准化输出都会被记录为Pod的日志,使用kubectl logs $POD_NAME 可以查看日志
$ kubectl logs $POD_NAME
Kubernetes Bootcamp App Started At: 2021-11-09T14:43:37.287Z | Running On: kubernetes-bootcamp-fb5c67579-zxj5k
Running On: kubernetes-bootcamp-fb5c67579-zxj5k | Total Requests: 1 | App Uptime: 300.278 seconds | Log Time: 2021-11-09T14:48:37.565Z
$
kubectl支持与容器内程序交互,可以通过kubectl exec pod-name 命令 查看环境变量
$ kubectl exec $POD_NAME -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=kubernetes-bootcamp-fb5c67579-zxj5k
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
NPM_CONFIG_LOGLEVEL=info
NODE_VERSION=6.3.1
HOME=/root
开启bash
$ kubectl exec -ti $POD_NAME -- bash
root@kubernetes-bootcamp-fb5c67579-zxj5k:/
|