- Kubernetes for Developers
- Joseph Heck
- 446字
- 2021-08-27 19:04:16
Running your container
Now, let's run the container we just made. We will use the kubectl run command as with the Python example, but replacing flask with nodejs to specify the container we just made and uploaded:
kubectl run nodejs --image=quay.io/kubernetes-for-developers/nodejs:0.2.0 --port=3000
deployment “nodejs” created
To see what it's doing, we need to ask the cluster for the current state of the resources we just created:
kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nodejs 1 1 1 1 1d
kubectl get pods
NAME READY STATUS RESTARTS AGE
nodejs-568183341-2bw5v 1/1 Running 0 1d
The kubectl run command works regardless of the language, and in the same fashion as the Python example. The simple deployment created in this case is named nodejs, and we can request the same kinds of information about it that we did with the Python example earlier:
kubectl get deployment nodejs -o json
The JSON output should will be fairly extensive, and will have multiple sections. At the top of the output will be apiVersion, kind, and metadata about the deployment:
{
"apiVersion": "extensions/v1beta1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "1"
},
"creationTimestamp": "2017-09-16T10:06:30Z",
"generation": 1,
"labels": {
"run": "nodejs"
},
"name": "nodejs",
"namespace": "default",
"resourceVersion": "88886",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/deployments/nodejs",
"uid": "b5d94f83-9ac6-11e7-884c-0aef48c812e4"
},
Typically, underneath that will be spec, which has a lot of the core of what you're just asked to be run:
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"run": "nodejs"
}
},
"strategy": {
"rollingUpdate": {
"maxSurge": 1,
"maxUnavailable": 1
},
"type": "RollingUpdate"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"run": "nodejs"
}
},
"spec": {
"containers": [
{
"image": "quay.io/kubernetes-for-developers/nodejs:0.2.0",
"imagePullPolicy": "IfNotPresent",
"name": "nodejs",
"ports": [
{
"containerPort": 3000,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File"
}
],
"dnsPolicy": "ClusterFirst",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"terminationGracePeriodSeconds": 30
}
}
},
And the final section is status, which indicates the current state (as of the request for this information) of the deployment:
"status": {
"availableReplicas": 1,
"conditions": [
{
"lastTransitionTime": "2017-09-16T10:06:30Z",
"lastUpdateTime": "2017-09-16T10:06:30Z",
"message": "Deployment has minimum availability.",
"reason": "MinimumReplicasAvailable",
"status": "True",
"type": "Available"
}
],
"observedGeneration": 1,
"readyReplicas": 1,
"replicas": 1,
"updatedReplicas": 1
}
}
When a Pod runs in Kubernetes, it is running in a sandbox, isolated from the rest of the world. Kubernetes does this intentionally, so you can specify what systems can communicate with each other, and what can be accessed from outside. For most clusters, the defaults for Kubernetes allow any Pod to communicate with any other Pod. Just like the Python example, you can leverage one of two commands with kubectl to get direct access from your development machine: kubectl port-forward or kubectl proxy.
- 后稀缺:自動(dòng)化與未來工作
- 腦動(dòng)力:Linux指令速查效率手冊
- Mastering Matplotlib 2.x
- PostgreSQL 11 Server Side Programming Quick Start Guide
- 程序設(shè)計(jì)缺陷分析與實(shí)踐
- Hybrid Cloud for Architects
- Visual Basic.NET程序設(shè)計(jì)
- Hands-On Reactive Programming with Reactor
- 液壓機(jī)智能故障診斷方法集成技術(shù)
- The DevOps 2.1 Toolkit:Docker Swarm
- 空間機(jī)器人
- TensorFlow Deep Learning Projects
- 設(shè)計(jì)模式
- Apache Spark Quick Start Guide
- Hands-On Geospatial Analysis with R and QGIS