- Getting Started with Kubernetes(Second Edition)
- Jonathan Baier
- 361字
- 2021-07-02 22:51:27
Pod example
Let's take a quick look at a pod in action. We will spin up a Node.js application on the cluster. You'll need a GCE cluster running for this; if you don't already have one started, refer to the Our first cluster section in Chapter 1, Introduction to Kubernetes.
Now, let's make a directory for our definitions. In this example, I will create a folder in the /book-examples subfolder under our home directory:
$ mkdir book-examples
$ cd book-examples
$ mkdir 02_example
$ cd 02_example
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Use your favorite editor to create the following file:
apiVersion: v1
kind: Pod
metadata:
name: node-js-pod
spec:
containers:
- name: node-js-pod
image: bitnami/apache:latest
ports:
- containerPort: 80
Listing 2-1: nodejs-pod.yaml
This file creates a pod named node-js-pod with the latest bitnami/apache container running on port 80. We can check this using the following command:
$ kubectl create -f nodejs-pod.yaml
The output is as follows:
pod "node-js-pod" created
This gives us a pod running the specified container. We can see more information on the pod by running the following command:
$ kubectl describe pods/node-js-pod
You'll see a good deal of information, such as the pod's status, IP address, and even relevant log events. You'll note the pod IP address is a private IP address, so we cannot access it directly from our local machine. Not to worry, as the kubectl exec command mirrors Docker's exec functionality. Once the pod shows to be in a running state, we can use this feature to run a command inside a pod:
$ kubectl exec node-js-pod -- curl <private ip address>
After running the command, you should see some HTML code. We'll have a prettier view later in the chapter, but for now, we can see that our pod is indeed running as expected.
- 輕松學(xué)C#
- JavaScript實(shí)例自學(xué)手冊(cè)
- 并行數(shù)據(jù)挖掘及性能優(yōu)化:關(guān)聯(lián)規(guī)則與數(shù)據(jù)相關(guān)性分析
- 城市道路交通主動(dòng)控制技術(shù)
- 高維聚類知識(shí)發(fā)現(xiàn)關(guān)鍵技術(shù)研究及應(yīng)用
- Implementing AWS:Design,Build,and Manage your Infrastructure
- 工業(yè)機(jī)器人安裝與調(diào)試
- ESP8266 Robotics Projects
- Photoshop CS4數(shù)碼照片處理入門、進(jìn)階與提高
- 工業(yè)機(jī)器人操作
- 大數(shù)據(jù)素質(zhì)讀本
- 算法設(shè)計(jì)與分析
- Red Hat Enterprise Linux 5.0服務(wù)器構(gòu)建與故障排除
- 工業(yè)機(jī)器人應(yīng)用系統(tǒng)三維建模
- 傳感器原理及應(yīng)用(第二版)