In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the use of kubernetes skills, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
One: get the IP of Pod in the container
ApiVersion: v1
Kind: ReplicationController
Metadata:
Name: world-v2
Spec:
Replicas: 3
Selector:
App: world-v2
Template:
Metadata:
Labels:
App: world-v2
Spec:
Containers:
-name: service
Image: test
Env:
-name: POD_IP
ValueFrom:
FieldRef:
FieldPath: status.podIP
Ports:
-name: service
ContainerPort: 777
The container's IP can be obtained directly by using the POD_IP environment variable in the container, which directly refers to the status field of the resource.
Second: obtain the host name, namespace, etc., in Pod
ApiVersion: v1
Kind: Pod
Metadata:
Name: dapi-test-pod
Spec:
Containers:
-name: test-container
Image: busybox
Command: ["/ bin/sh", "- c", "env"]
Env:
-name: MY_NODE_NAME
ValueFrom:
FieldRef:
FieldPath: spec.nodeName
-name: MY_POD_NAME
ValueFrom:
FieldRef:
FieldPath: metadata.name
-name: MY_POD_NAMESPACE
ValueFrom:
FieldRef:
FieldPath: metadata.namespace
-name: MY_POD_IP
ValueFrom:
FieldRef:
FieldPath: status.podIP
-name: HOST_IP
ValueFrom:
FieldRef:
FieldPath: status.hostIP
-name: MY_POD_SERVICE_ACCOUNT
ValueFrom:
FieldRef:
FieldPath: spec.serviceAccountName
RestartPolicy: Never
This tip complements the first item to get the podIP, all in the same way, except that more reference fields are listed. Referring to the pod definition below, there is a {.spec.nodeName} field in each pod. Through fieldRef and environment variables, the host name of the host can be obtained in Pod (access to the environment variable MY_NODE_NAME).
Third, specify the startup parameters of the container
We can specify startup parameters for containers in Pod using command for containers:
Command: ["/ bin/bash", "- c", "bootstrap.sh"]
Defined as an array, all commands use the same CMD configuration as in Dockerfile, but one difference is that bootsttap.sh must have executable permissions, otherwise the container will make an error when it starts.
Fourth: synchronize the time in the container with the host
The time zone in many of the containers we downloaded is GMT, which is 8 hours behind Beijing time, which will cause the creation time of logs and files in the container to be inconsistent with the actual time zone. There are two ways to solve this problem:
1. Modify the time zone profile in the mirror
two。 Mount the host's time zone configuration file / etc/localtime into the container using volume
The second method is relatively simple. There is no need to redo the image, just add the following configuration to the yaml file of the application:
VolumeMounts:
-name: host-time
MountPath: / etc/localtime
ReadOnly: true
Volumes:
-name: host-time
HostPath:
Path: / etc/localtime
Five: kubectl command completion
# yum install-y bash-completion
# source / usr/share/bash-completion/bash_completion
# source
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.