committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 246 additions and 0 deletions
Unified View
Diff Options
-
1README.md
-
1docs/_sidebar.md
-
41docs/ntp.md
-
10inventory/sample/group_vars/all/all.yml
-
37roles/kubernetes/preinstall/defaults/main.yml
-
6roles/kubernetes/preinstall/handlers/main.yml
-
65roles/kubernetes/preinstall/tasks/0081-ntp-configurations.yml
-
7roles/kubernetes/preinstall/tasks/main.yml
-
27roles/kubernetes/preinstall/templates/chrony.conf.j2
-
45roles/kubernetes/preinstall/templates/ntp.conf.j2
-
6tests/files/packet_almalinux8-calico.yml
@ -0,0 +1,41 @@ |
|||||
|
# NTP synchronization |
||||
|
|
||||
|
The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems. Time synchronization is important to Kubernetes and Etcd. |
||||
|
|
||||
|
## Enable the NTP |
||||
|
|
||||
|
To start the ntpd(or chrony) service and enable it at system boot. There are related specific variables: |
||||
|
|
||||
|
```ShellSession |
||||
|
ntp_enabled: true |
||||
|
``` |
||||
|
|
||||
|
The NTP service would be enabled and sync time automatically. |
||||
|
|
||||
|
## Custimize the NTP configure file |
||||
|
|
||||
|
In the Air-Gap environment, the node cannot access the NTP server by internet. So the node can use the customized ntp server by configuring ntp file. |
||||
|
|
||||
|
```ShellSession |
||||
|
ntp_enabled: true |
||||
|
ntp_manage_config: true |
||||
|
ntp_servers: |
||||
|
- "0.your-ntp-server.org iburst" |
||||
|
- "1.your-ntp-server.org iburst" |
||||
|
- "2.your-ntp-server.org iburst" |
||||
|
- "3.your-ntp-server.org iburst" |
||||
|
``` |
||||
|
|
||||
|
## Advanced Configure |
||||
|
|
||||
|
Enable `tinker panic` is useful when running NTP in a VM environment to avoiding clock drift on VMs. It only takes effect when ntp_manage_config is true. |
||||
|
|
||||
|
```ShellSession |
||||
|
ntp_tinker_panic: true |
||||
|
``` |
||||
|
|
||||
|
Force sync time immediately by NTP after the ntp installed, which is useful in newly installed system. |
||||
|
|
||||
|
```ShellSession |
||||
|
ntp_force_sync_immediately: true |
||||
|
``` |
@ -0,0 +1,65 @@ |
|||||
|
--- |
||||
|
- name: Ensure NTP package |
||||
|
package: |
||||
|
name: |
||||
|
- "{{ ntp_package }}" |
||||
|
state: present |
||||
|
|
||||
|
- name: Disable systemd-timesyncd |
||||
|
service: |
||||
|
name: systemd-timesyncd.service |
||||
|
enabled: false |
||||
|
state: stopped |
||||
|
failed_when: false |
||||
|
|
||||
|
- name: Set fact NTP settings |
||||
|
set_fact: |
||||
|
ntp_config_file: >- |
||||
|
{% if ntp_package == "ntp" -%} |
||||
|
/etc/ntp.conf |
||||
|
{%- elif ansible_os_family in ['RedHat', 'Suse'] -%} |
||||
|
/etc/chrony.conf |
||||
|
{%- else -%} |
||||
|
/etc/chrony/chrony.conf |
||||
|
{%- endif -%} |
||||
|
ntp_service_name: >- |
||||
|
{% if ntp_package == "chrony" -%} |
||||
|
chronyd |
||||
|
{%- elif ansible_os_family == 'RedHat' -%} |
||||
|
ntpd |
||||
|
{%- else -%} |
||||
|
ntp |
||||
|
{%- endif %} |
||||
|
|
||||
|
- name: Generate NTP configuration file. |
||||
|
template: |
||||
|
src: "{{ ntp_config_file | basename }}.j2" |
||||
|
dest: "{{ ntp_config_file }}" |
||||
|
mode: 0644 |
||||
|
notify: Preinstall | restart ntp |
||||
|
when: |
||||
|
- ntp_manage_config |
||||
|
|
||||
|
- name: Stop the NTP Deamon For Sync Immediately # `ntpd -gq`,`chronyd -q` requires the ntp daemon stop |
||||
|
service: |
||||
|
name: "{{ ntp_service_name }}" |
||||
|
state: stopped |
||||
|
when: |
||||
|
- ntp_force_sync_immediately |
||||
|
|
||||
|
- name: Force Sync NTP Immediately |
||||
|
command: >- |
||||
|
timeout -k 60s 60s |
||||
|
{% if ntp_package == "ntp" -%} |
||||
|
ntpd -gq |
||||
|
{%- else -%} |
||||
|
chronyd -q |
||||
|
{%- endif -%} |
||||
|
when: |
||||
|
- ntp_force_sync_immediately |
||||
|
|
||||
|
- name: Ensure NTP service is started and enabled |
||||
|
service: |
||||
|
name: "{{ ntp_service_name }}" |
||||
|
state: started |
||||
|
enabled: true |
@ -0,0 +1,27 @@ |
|||||
|
# {{ ansible_managed }} |
||||
|
|
||||
|
# Specify one or more NTP servers. |
||||
|
# Use public servers from the pool.ntp.org project. |
||||
|
# Please consider joining the pool (http://www.pool.ntp.org/join.html). |
||||
|
{% for server in ntp_servers %} |
||||
|
server {{ server }} |
||||
|
{% endfor %} |
||||
|
|
||||
|
# Record the rate at which the system clock gains/losses time. |
||||
|
driftfile /var/lib/chrony/drift |
||||
|
|
||||
|
{% if ntp_tinker_panic is sameas true %} |
||||
|
# Force time sync if the drift exceeds the threshold specified |
||||
|
# Usefull for VMs that can be paused and much later resumed. |
||||
|
makestep 1.0 -1 |
||||
|
{% else %} |
||||
|
# Allow the system clock to be stepped in the first three updates |
||||
|
# if its offset is larger than 1 second. |
||||
|
makestep 1.0 3 |
||||
|
{% endif %} |
||||
|
|
||||
|
# Enable kernel synchronization of the real-time clock (RTC). |
||||
|
rtcsync |
||||
|
|
||||
|
# Specify directory for log files. |
||||
|
logdir /var/log/chrony |
@ -0,0 +1,45 @@ |
|||||
|
# {{ ansible_managed }} |
||||
|
|
||||
|
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help |
||||
|
|
||||
|
driftfile {{ ntp_driftfile }} |
||||
|
|
||||
|
{% if ntp_tinker_panic is sameas true %} |
||||
|
# Always reset the clock, even if the new time is more than 1000s away |
||||
|
# from the current system time. Usefull for VMs that can be paused |
||||
|
# and much later resumed. |
||||
|
tinker panic 0 |
||||
|
{% endif %} |
||||
|
|
||||
|
# Specify one or more NTP servers. |
||||
|
# Use public servers from the pool.ntp.org project. |
||||
|
# Please consider joining the pool (http://www.pool.ntp.org/join.html). |
||||
|
{% for item in ntp_servers %} |
||||
|
pool {{ item }} |
||||
|
{% endfor %} |
||||
|
|
||||
|
# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for |
||||
|
# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions> |
||||
|
# might also be helpful. |
||||
|
# |
||||
|
# Note that "restrict" applies to both servers and clients, so a configuration |
||||
|
# that might be intended to block requests from certain clients could also end |
||||
|
# up blocking replies from your own upstream servers. |
||||
|
|
||||
|
# By default, exchange time with everybody, but don't allow configuration. |
||||
|
restrict -4 default kod notrap nomodify nopeer noquery limited |
||||
|
restrict -6 default kod notrap nomodify nopeer noquery limited |
||||
|
|
||||
|
# Local users may interrogate the ntp server more closely. |
||||
|
{% for item in ntp_restrict %} |
||||
|
restrict {{ item }} |
||||
|
{% endfor %} |
||||
|
|
||||
|
# Needed for adding pool entries |
||||
|
restrict source notrap nomodify noquery |
||||
|
|
||||
|
# Disable the monitoring facility to prevent amplification attacks using ntpdc |
||||
|
# monlist command when default restrict does not include the noquery flag. See |
||||
|
# CVE-2013-5211 for more details. |
||||
|
# Note: Monitoring will not be disabled with the limited restriction flag. |
||||
|
disable monitor |
Write
Preview
Loading…
Cancel
Save