官术网_书友最值得收藏!

  • Learn OpenShift
  • Denis Zuev Artemii Kropachev Aleksey Usov
  • 259字
  • 2021-08-13 16:03:53

Creating kubernetes services using YAML and JSON files

You can also create Kubernetes resources manually using YAML and JSON files. Let's go ahead and create a simple pod running a httpd web server using the kubectl create command. We will have to create a YAML-formatted file:

$ cat httpd-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: httpd
namespace: default
spec:
containers:
- name: httpd-container
image: httpd
ports:
- containerPort: 80
Reading YAML and JSON-formatted files is critical for Kubernetes and for later, in the OpenShift chapter. If you feel uncomfortable reading YAML or JSON files, read up on these subjects. Check the Further reading section for more information.

It may look a bit complicated and hard to understand, but as we move on in this book, you will see a lot of similarities between these YAML and JSON files. 

YAML configuration files are very structured and each resource is a set of keys and values. You can use the Kuberentes API documentation to find out what every parameter does:  https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/.

Create a pod using the httpd-pod.yaml file:

$ kubectl create -f httpd-pod.yaml

$ kubectl get all
NAME READY STATUS RESTARTS AGE
po/httpd 1/1 Running 0 25s

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 56s

This command creates a pod named httpd; it does not create anything else. In larger deployments with heavy automation involved, this is the way to deploy Kubernetes resources, but this, of course, requires better Kubernetes skills.

Similarly, we can create other Kubernetes resources, including ReplicaSet, Deployment, and others.

主站蜘蛛池模板: 漳州市| 神木县| 亚东县| 凤山县| 隆化县| 临颍县| 朝阳区| 丰台区| 宜兰县| 哈巴河县| 沾化县| 林西县| 铜陵市| 新津县| 天全县| 林甸县| 昌图县| 丰台区| 区。| 横峰县| 鞍山市| 墨竹工卡县| 莎车县| 宁乡县| 无锡市| 双牌县| 安新县| 盐源县| 阿尔山市| 建湖县| 顺义区| 海兴县| 拉孜县| 宁国市| 清新县| 贺州市| 伊宁市| 平安县| 云和县| 全南县| 徐汇区|